Created
June 22, 2015 09:19
-
-
Save cefn/7fd3504a0b29575f3b6f to your computer and use it in GitHub Desktop.
Mocha test which successfully tests zipped stream (using onValues to force side effects).
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"), | |
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); | |
//adding lines below causes test to fail | |
//actualSequence.pop(); | |
//actualSequence.push(["oldmacdonald/farm/horse", "'Neigh'"]); | |
var targetStream = Bacon.sequentially(0, targetSequence); | |
var actualStream = Bacon.sequentially(0, actualSequence); | |
//var targetStream = Bacon.fromArray(targetSequence); | |
//var actualStream = Bacon.fromArray(actualSequence); | |
var deepEqual = function(target, actual){ | |
console.log("Testing " + JSON.stringify(target) + " versus " + JSON.stringify(actual) + "..."); | |
assert.deepEqual(target, actual); | |
return true; | |
}; | |
var zippedStream = Bacon.zipAsArray(targetStream, actualStream); | |
zippedStream.onValues(deepEqual); | |
return zippedStream.toPromise() | |
.finally(function(){ | |
console.log("Stream finished"); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment