How to mock API calls made within a React component being tested with Jest
I'm trying to mock a fetch() that retrieves data into a component. I'm using this as a model for mocking my fetches, but I'm having trouble getting it to work. I'm getting this error when I run my tests: babel-plugin-jest-hoist: The module factory of 'jest.mock()' is not allowed to reference any out-of-scope variables. Is there a way I can have these functions return mock data instead of actually trying to make real API calls? Code utils/getUsers.js Returns users with roles mapped into each user. const getUsersWithRoles = rolesList => fetch(`/users`, { credentials: "include" }).then(response =
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.