Created
March 19, 2015 22:07
-
-
Save rogeriochaves/937848ab4a5f383c2c6c to your computer and use it in GitHub Desktop.
Testing RxJS Observables on Jasmine 1.3
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
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs/2.4.3/rx.all.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs/2.4.3/rx.testing.min.js"></script> | |
<script src="http://daniellmb.github.com/jasmine-run/jasmine-1.3.1-run.js"></script> | |
<script> | |
var waitsForObservable = function (observable, callback, opt_timeout) { | |
var result, timeout; | |
timeout = opt_timeout || 5000; | |
runs(function(){ | |
observable.toArray().forEach(function (arr) { | |
result = arr; | |
}); | |
}); | |
waitsFor(function(){ | |
return result; | |
}, 'observable should be completed', timeout); | |
runs(function() { | |
callback(result); | |
}); | |
} | |
var exampleObservable = Rx.Observable.interval(500).take(5).map(function(){ | |
return "x" | |
}); | |
describe("Rx Observable testing", function() { | |
it("compares observable equality", function() { | |
waitsForObservable(exampleObservable, function(result){ | |
expect(result).toEqual(["x", "x", "x", "x", "x"]); | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment