Skip to content
Advertisement

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 something like: Answer Since you would want

String concatenation returning undefined on Jest test snapshot

I have the following react component and I am writing my tests like this Problem is when it is creating the snapshot, the type variable is returning undefined. I assume it has something to do with the string concatenation, because the “role” variable is writing correctly. here is the snapshot. So, I am not sure what I am missing here

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 of request.post, just choose one

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 gets transpiled, as you can see

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 Expo thread mentioning the exact same issue here. It looks like you’re using jest-expo v39 with a project running SDK37. LogBox was released with React

Using Spies and Mocks on complex objects with Jest

I’m fairly new to testing and writing tests for a currently uncovered javaScript codebase using Jest. The code covers some niche use cases, as its conditionally injected and executed by the browser during page load. Anyway, I’m having issues mocking up custom objects. Here’s the function in question: As far as I understand, I need to mock both window.location.pathname to

Jest | TypeError: window.URL.createObjectURL is not a function

This issue happens due to be using mapbox-gl in a React project. I’m aware that there are solutions like this but due to me being a junior I fail to completely comprehend what I should do to solve. I don’t have any setupTest.js or jest.stubs.js Creating them appears to do nothing for my test suites. I’m using ftw-hourly for this

Advertisement