Created
February 17, 2020 16:04
-
-
Save keithstric/83b8e682485747851f9b2747bffb149a to your computer and use it in GitHub Desktop.
Adventures in Unit Testing 3
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 someFunction = require('./index'); | |
const rewire = require('rewire'); | |
let app; | |
beforeEach(() => { | |
someFunction(); | |
app = rewire('./index.js'); | |
}); | |
test('it should increment evtCount', () => { | |
const evtCount = app.__get__('evtCount'); | |
const somePrivateFunc = app.__get__('somePrivateFunction'); | |
somePrivateFunc(); | |
expect(evtCount).toEqual(1); | |
}); | |
test('it should call somePrivateFunction on the foo event', () => { | |
const privateFuncMock = jest.fn(); | |
app.__set__('somePrivateFunction', privateFuncMock); | |
const emitter = app.__get__('customEmitter'); | |
emitter.emit('foo', 'bar'); | |
expect(privateFuncMock).toHaveBeenCalled(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment