Skip to content

Tag: jestjs

mock node config with jest

I introduce myself currently for the first time in jest and nodejs. I am facing the problem that I have to mock two different values from the nodejs config. the problem is that the second mockReturnValue overwrites the first one. is there any possibility to separate booth mocks from each other? Maybe with som…

Jest Unit test + received undefined

I am using Jest as my unit test framework. I am trying to mock third part npm “request” and executed my test cases, but i am receiving and the test fails The following is my code: spec.js Ctrl.js Please share your ideas. Thanks in adavnce. Answer You don’t need to use await with the callback…

How to mock/spy useState hook in jest?

I am trying to spy on useState React hook but i always get the test failed This is my React component: counter.test.js: Unfortunately this doesn’t work and i get the test failed with that message: Answer You need to use React.useState instead of the single import useState. I think is about how the code …

Jest testcase breaking in React Native Expo

Following is the error I receive on running a Sample testcase: My Testcase: My jest configuration in package.json: My dependencies in package.json: expo version: 37.0.0 react: `16.9.0 react-native: “https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz” Answer Found the solution on the Ex…