How can you mock a module dependency in Jest for unit testing?
- Using the requireMock() function.
- Utilizing the jest.mock() function.
- Adding a __mocks__ folder in your project.
- Manually overriding the module's code in the test.
To mock a module dependency in Jest for unit testing, you should utilize the jest.mock() function. This allows you to specify the module you want to mock and provide a custom implementation or mock for that module. The other options are not the standard ways to mock module dependencies in Jest.
Loading...
Related Quiz
- You're tasked with building a PWA for a ticket booking platform. The requirement is to ensure users can view their booked tickets even when offline. How would you implement this functionality?
- In Next.js, how can you generate static pages at build time for better performance?
- What is the main advantage of using fireEvent from React Testing Library?
- How can TypeScript enhance the development experience in a large-scale React project?
- The process by which a service worker takes control of a page and becomes active is known as ________.