Last active
August 29, 2015 14:01
-
-
Save jeffmo/8d33a29fd5f3e58f0ace to your computer and use it in GitHub Desktop.
This file contains 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
// SomeEmitter.js | |
function SomeEmitter() {} | |
SomeEmitter.prototype.on = function() {}; | |
SomeEmitter.prototype.emit = function() {}; | |
module.exports = SomeEmitter; |
This file contains 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
// __mocks__/SomeEmitter.js | |
/** | |
* This is a manual mock that Jest will look for before it | |
* tries to automatically generate a mock itself. | |
* | |
* For more details: | |
* http://facebook.github.io/jest/docs/manual-mocks.html | |
*/ | |
var SomeEmitter = require.generateMock('../SomeEmitter'); | |
SomeEmitter.prototype.on.mockReturnThis(); | |
SomeEmitter.prototype.emit.mockReturnThis(); | |
module.exports = SomeEmitter; |
This file contains 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
// __tests__/MyThingThatUsesSomeEmitter-test.js | |
describe('This is a test', function() { | |
it('is only a test', function() { | |
var SomeEmitter = require('../SomeEmitter'); | |
var emitter = new SomeEmitter; | |
emitter.on('foo').emit('bar'); | |
expect(emitter.on).toBeCalledWith('foo'); | |
expect(emitter.emit).toBeCalledWith('bar'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment