Last active
March 28, 2016 15:49
-
-
Save mikeauclair/101090ed9c050d812b11 to your computer and use it in GitHub Desktop.
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
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