Skip to content

Instantly share code, notes, and snippets.

@johannhof
Created October 17, 2015 11:44
Show Gist options
  • Save johannhof/b47fe3ef7d07caf730fe to your computer and use it in GitHub Desktop.
Save johannhof/b47fe3ef7d07caf730fe to your computer and use it in GitHub Desktop.
Bacon Jest mocking troubles
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 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