Last active
January 5, 2023 17:50
-
-
Save acatl/965865aae86cf135f1cfc621a4a86fcc to your computer and use it in GitHub Desktop.
jest mock debug.js module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-env jest */ | |
const mockDebug = jest.fn() | |
jest.mock('debug', () => { | |
return () => mockDebug | |
}) | |
const foo = require('./foo') | |
describe('foo.bar', () => { | |
it('should testName', () => { | |
mockDebug.mockClear() | |
mockDebug.mockReset() | |
foo.bar() | |
expect(mockDebug).toBeCalled() | |
expect(mockDebug.mock.calls).toMatchSnapshot() | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debug = require('debug')('foo') | |
function bar () { | |
debug('hello world') | |
} | |
module.exports = { | |
bar | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
exmaple: typescript + jest + mock debug.js module