Skip to content
Advertisement

Tag: unit-testing

Module not found even though it is imported

When I run this test: I get this error: Reissue.tsx does import ReissueService. Do I need to mock this and if so how do I do that? In Reissue my import is: and I’m exporting: In ReissueService I export: Answer I changed import { ReissueService } from ‘src/services/ReissueService/ReissueService’; to import { ReissueService } from ‘../../services/ReissueService/ReissueService’;

How to mock instance methods of a class mocked with jest.mock?

How can the instance methods be mocked for a class that is being mocked with jest.mock? For example, a class Logger is mocked: Answer Automatic Mocking Calling jest.mock automatically mocks all the exports from the module being mocked unless a manual mock is specified using the __mocks__ directory. So, this line jest.mock(“./Logger”) has automatically replaced the Logger constructor and all

Debugging jest mocks

I’ve got a library that’s giving me some trouble in my jest tests. This library is included throughout my project, and it has an annoyingFunction that has a console.error in it. So, whenever I run a test, I naturally get unwanted console.error messages all over the place. I don’t want to mock out the whole library, just the annoyingFunction, so

TypeError: Cannot read property ‘navigator’ of undefined

My unit test case started failing when I started running the unit test in mocha from karma, Earlier we were using karma and –browser to run the test case but it was running fine, Package.json test file – It fails for navigator here, TypeError: Cannot read property ‘navigator’ of undefined ReferenceError: navigator is not defined Answer Accessing global.window.navigator is an

Jest: Failed prop type: Invalid prop `source` supplied to `Image`, expected one of type [number]

I am using jest with react-native to run unit test cases. And whenever it encounters Image it throws the following warning I tried to replace the code to as suggested in https://stackoverflow.com/a/36460928/3855179 but it started throwing the following warning and the application breaks Any idea how this can be handled? Answer It would be helpful to see your file structure

Module pattern variable returning undefined in test?

I have the following code below which returns certain data depending on NODE_ENV: config.js This works well in my component when I set NODE_ENV. However in my test, I keep getting undefined as a result. config.test.js Again, Config.data works fine in my React component when I start it up, but I guess I need to somehow initialize this for it

Issue with setting up jest mock

I have the following function that is used within cypress tests for which I want to do unit testing (filterTests.js): A test double for Cypress.env needs to be created. I’m not sure if this would technically be considered a stub, mock, fake, dummy, etc…, but the philosophical discussion isn’t the focus right now. It looks like in the Cypress world,

Advertisement