Skip to content

Commit

Permalink
fix(TestScheduler): ensure TestScheduler subscribes to expectations b…
Browse files Browse the repository at this point in the history
…efore hot subjects
  • Loading branch information
benlesh committed Sep 15, 2015
1 parent 7a15304 commit b9b2ba5
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/schedulers/TestScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Notification from '../Notification';
import Subject from '../Subject';

export default class TestScheduler extends VirtualTimeScheduler {
private hotObservables: { setup: (scheduler: TestScheduler) => void, subject: Subject<any> }[] = [];

constructor(public assertDeepEqual: (actual: any, expected: any) => boolean | void) {
super();
}
Expand All @@ -22,14 +24,19 @@ export default class TestScheduler extends VirtualTimeScheduler {
});
}

createHotObservable(marbles: string, values?: any, error?: any) {
createHotObservable<T>(marbles: string, values?: any, error?: any): Subject<T> {
let messages = TestScheduler.parseMarbles(marbles, values, error);
let subject = new Subject();
messages.forEach(({ notification, frame }) => {
this.schedule(() => {
notification.observe(subject);
}, frame);
}, this);
this.hotObservables.push({
setup(scheduler) {
messages.forEach(({ notification, frame }) => {
scheduler.schedule(() => {
notification.observe(subject);
}, frame);
});
},
subject
});
return subject;
}

Expand Down Expand Up @@ -62,7 +69,12 @@ export default class TestScheduler extends VirtualTimeScheduler {
};
}

flush() {
flush() {
const hotObservables = this.hotObservables;
while(hotObservables.length > 0) {
hotObservables.shift().setup(this);
}

super.flush();
const flushTests = this.flushTests.filter(test => test.ready);
while (flushTests.length > 0) {
Expand Down

0 comments on commit b9b2ba5

Please sign in to comment.