Skip to content

Instantly share code, notes, and snippets.

@mikeauclair
Last active March 28, 2016 15:49
Show Gist options
  • Save mikeauclair/101090ed9c050d812b11 to your computer and use it in GitHub Desktop.
Save mikeauclair/101090ed9c050d812b11 to your computer and use it in GitHub Desktop.
describe('example', function() {
beforeEach(function(){
var scheduler = this.scheduler = new Rx.TestScheduler();
this.userEmails = this.scheduler.createHotObservable(
Rx.ReactiveTest.onNext(
210,
{email: '[email protected]'}
),
Rx.ReactiveTest.onCompleted(215)
);
this.getUserName = function(userEmail){
return getUserData().then(function(userData){
return userData.name;
});
};
var getUserData = function(){
return scheduler.createResolvedPromise(220, {name: "Bob"});
};
});
it('should grab data to render the user', function(done) {
var uName;
this.userEmails.flatMapLatest(this.getUserName, this.scheduler).subscribe(function(name){
uName = name;
});
this.scheduler.advanceTo(221);
this.scheduler.stop();
Rx.Scheduler.async.schedule(true, function(){
// This will fail with uName being {name: "Bob"}, the result of the outer promise
expect(uName).toEqual('Bob');
done();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment