Skip to content

Instantly share code, notes, and snippets.

@cefn

cefn/zip-mocha-test

Created Jun 22, 2015
Embed
What would you like to do?
Mocha Test of .zip laziness
var Bacon = require("baconjs"),
assert = require("assert");
require('promise.prototype.finally');
describe("Testing stream equality logic", function(){
it( "can match Bacon streams backed by the same array.", function(){
var targetSequence = [
["oldmacdonald/farm", "['sheep','pig','cow','duck']" ] , //n.b. JSON.stringify of array
["oldmacdonald/farm/sheep", "'Baa'"] , //n.b. JSON.stringify of string (quoted)
["oldmacdonald/farm/pig", "'Oink'"] ,
["oldmacdonald/farm/cow", "'Moo'"] ,
["oldmacdonald/farm/duck", "'Quack'"] ,
];
var actualSequence = targetSequence.slice(0);
actualSequence.push(["oldmacdonald/farm/horse", "'Neigh'"]);
var targetStream = Bacon.fromArray(targetSequence);
var actualStream = Bacon.fromArray(actualSequence);
//var targetStream = Bacon.sequentially(0, targetSequence);
//var actualStream = Bacon.sequentially(0, actualSequence);
var deepEqual = function(target, actual){
console.log("Testing " + JSON.stringify(target) + " versus " + JSON.stringify(actual) + "...");
assert.deepEqual(target, actual);
return true;
};
var receivePromise = targetStream.zip(actualStream, deepEqual)
.toPromise()
.finally(function(){
console.log("Stream finished");
});
return receivePromise;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment