You have to use global
to access objects in the global context
global.console = {warn: jest.fn()}
expect(console.warn).toBeCalled()
or use jest.spyOn
added in 19.0.0
jest.spyOn(global.console, 'warn')
More Related Contents:
- JavaScript unit test tools for TDD
- Mocking globals in Jest
- How to test the type of a thrown exception in Jest
- How to change the behaviour of a mocked import?
- What functions should I mock during unit testing
- How to mock Axios with Jest?
- How to mock dependencies for unit tests with ES6 Modules
- How to mock functions in the same module using Jest?
- Jest mock inner function
- How can I mock the JavaScript window object using Jest?
- jasmine: Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL
- Mocking a useragent in javascript?
- Change default timeout for mocha
- Can you write async tests that expect toThrow?
- How to mock localStorage in JavaScript unit tests?
- Angular ui router unit testing (states to urls)
- How can I mock dependencies for unit testing in RequireJS?
- How to spyOn a value property (rather than a method) with Jasmine
- Is there a way to get Chai working with asynchronous Mocha tests?
- How to trigger script.onerror in Internet Explorer?
- How can I mock the imports of an ES6 module?
- jest unexpected token when importing css
- Jest – SyntaxError: Cannot use import statement outside a module
- Mock inner axios.create()
- Mocking and Stubbing with protractor
- Remove logging the origin line in Jest
- Mocking dayjs extend
- Jest spyOn function called
- Is it possible to put test files under pages directory in Next.js?
- how to fix 404 warnings for images during karma unit testing