Skip to content

Commit

Permalink
fix(fakeSchedulers): Support asapScheduler.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jun 10, 2018
1 parent ce2446d commit e510698
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
10 changes: 9 additions & 1 deletion fixtures/jasmine/passing-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "zone.js/dist/jasmine-patch";
import "zone.js/dist/async-test";
import "zone.js/dist/fake-async-test";

import { of, timer } from "rxjs";
import { asapScheduler, of, timer } from "rxjs";
import { delay, map, tap } from "rxjs/operators";
import { cases, DoneFunction, marbles, observe } from "../../dist/jasmine";
import { fakeSchedulers } from "../../dist/jasmine/angular";
Expand Down Expand Up @@ -136,4 +136,12 @@ describe("fakeSchedulers", () => {
tick(50);
expect(received).toBe(1);
}));

it("should support the asapScheduler", fakeSchedulers(tick => {
let received: number | undefined;
of(1).pipe(delay(0, asapScheduler)).subscribe(value => received = value);
expect(received).not.toBeDefined();
tick(0);
expect(received).toBe(1);
}));
});
10 changes: 9 additions & 1 deletion fixtures/jest/passing-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
/*tslint:disable:object-literal-sort-keys*/

import { of, timer } from "rxjs";
import { asapScheduler, of, timer } from "rxjs";
import { delay, map, tap } from "rxjs/operators";
import { cases, DoneFunction, fakeSchedulers, marbles, observe } from "../../dist/jest";

Expand Down Expand Up @@ -128,4 +128,12 @@ describe("fakeSchedulers", () => {
advance(50);
expect(received).toBe(1);
}));

test("it should support the asapScheduler", fakeSchedulers(advance => {
let received: number | undefined;
of(1).pipe(delay(0, asapScheduler)).subscribe(value => received = value);
expect(received).not.toBeDefined();
advance(0);
expect(received).toBe(1);
}));
});
4 changes: 3 additions & 1 deletion source/jest/fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* can be found in the LICENSE file at https://github.com/cartant/rxjs-marbles
*/

import { asyncScheduler } from "rxjs";
import { asapScheduler, asyncScheduler } from "rxjs";

declare const jest: any;

Expand All @@ -13,12 +13,14 @@ export function fakeSchedulers(
return () => {
try {
let fakeTime = 0;
asapScheduler.schedule = asyncScheduler.schedule.bind(asyncScheduler);
asyncScheduler.now = () => fakeTime;
fakeTest(milliseconds => {
fakeTime += milliseconds;
jest.advanceTimersByTime(milliseconds);
});
} finally {
delete asapScheduler.schedule;
delete asyncScheduler.now;
}
};
Expand Down

0 comments on commit e510698

Please sign in to comment.