Created
October 17, 2015 11:44
-
-
Save johannhof/b47fe3ef7d07caf730fe to your computer and use it in GitHub Desktop.
Bacon Jest mocking troubles
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
var Bacon = require('baconjs'); | |
var anotherStream = require('./example2'); | |
module.exports = Bacon | |
.once("wow") | |
// if `anotherStream` is from another JS context, | |
// e.g. mocked from jest, this will fail (it shouldn't) | |
.merge(anotherStream); | |
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
// this example will throw the following error | |
// example.js: not an EventStream : Bacon.once(yay) | |
// using my branch from https://github.com/baconjs/bacon.js/pull/639, | |
// it will work correctly | |
var Bacon = require('baconjs'); | |
jest.dontMock('../example.js'); | |
describe('stream', function() { | |
beforeEach(function(){ | |
// this will not work, although it's a great feature | |
jest.setMock('../example2.js', Bacon.once("yay")); | |
}); | |
pit('streams', function(){ | |
var stream = require('../example.js'); | |
return new Promise(function(res, rej){ | |
stream.slidingWindow(2,2).onValue(function(val){ | |
expect(val).toEqual(["wow", "yay"]); | |
res(); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment