Skip to content

Commit 8acd37b

Browse files
committed
fix(faketime): fix fakeTime for RxJS 7
fix breaking changes of RxJS 7 that break the fakeTime util fix #39
1 parent 00ee48a commit 8acd37b

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"prettier": "2.0.5",
6868
"pretty-quick": "2.0.1",
6969
"rimraf": "3.0.2",
70-
"rxjs": "^6.5.5",
70+
"rxjs": "~7.4.0",
7171
"semantic-release": "^17.0.7",
7272
"travis-deploy-once": "^5.0.11",
7373
"ts-jest": "^25.4.0",

src/fake-time.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { VirtualTimeScheduler } from 'rxjs';
2-
import { AsyncScheduler } from 'rxjs/internal/scheduler/AsyncScheduler';
1+
import { TestScheduler } from 'rxjs/testing';
32

43
export function fakeTime(callback: (...args: any[]) => any) {
54
if (callback.length === 0) {
@@ -11,31 +10,21 @@ export function fakeTime(callback: (...args: any[]) => any) {
1110

1211
if (callback.length === 1) {
1312
return function () {
14-
const virtualScheduler = new VirtualTimeScheduler();
15-
AsyncScheduler.delegate = virtualScheduler;
13+
/* istanbul ignore next */
14+
const testScheduler = new TestScheduler(() => {});
1615

17-
function customFlush() {
18-
virtualScheduler.flush();
19-
}
20-
const originalReturnedValue = callback(customFlush);
21-
22-
AsyncScheduler.delegate = undefined;
23-
24-
return originalReturnedValue;
16+
return testScheduler.run(({ flush }) => {
17+
return callback(flush);
18+
});
2519
};
2620
}
2721

2822
return function (done: () => void) {
29-
const virtualScheduler = new VirtualTimeScheduler();
30-
AsyncScheduler.delegate = virtualScheduler;
31-
32-
function customFlush() {
33-
virtualScheduler.flush();
34-
}
35-
const originalReturnedValue = callback(customFlush, done);
36-
37-
AsyncScheduler.delegate = undefined;
23+
/* istanbul ignore next */
24+
const testScheduler = new TestScheduler(() => {});
3825

39-
return originalReturnedValue;
26+
return testScheduler.run(({ flush }) => {
27+
return callback(flush, done);
28+
});
4029
};
4130
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"emitDecoratorMetadata": true,
77
"declaration": true, // generate .d.ts files
88
"declarationMap": true,
9-
"noImplicitAny": true,
9+
"noImplicitAny": false,
1010
"esModuleInterop": true,
1111
"sourceMap": true,
1212
"downlevelIteration": true,

yarn.lock

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7618,13 +7618,20 @@ run-queue@^1.0.0, run-queue@^1.0.3:
76187618
dependencies:
76197619
aproba "^1.1.1"
76207620

7621-
rxjs@^6.4.0, rxjs@^6.5.3, rxjs@^6.5.5:
7621+
rxjs@^6.4.0, rxjs@^6.5.3:
76227622
version "6.5.5"
76237623
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.5.tgz#c5c884e3094c8cfee31bf27eb87e54ccfc87f9ec"
76247624
integrity sha512-WfQI+1gohdf0Dai/Bbmk5L5ItH5tYqm3ki2c5GdWhKjalzjg93N3avFjVStyZZz+A2Em+ZxKH5bNghw9UeylGQ==
76257625
dependencies:
76267626
tslib "^1.9.0"
76277627

7628+
rxjs@~7.4.0:
7629+
version "7.4.0"
7630+
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.4.0.tgz#a12a44d7eebf016f5ff2441b87f28c9a51cebc68"
7631+
integrity sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w==
7632+
dependencies:
7633+
tslib "~2.1.0"
7634+
76287635
safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0:
76297636
version "5.2.1"
76307637
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
@@ -8516,6 +8523,11 @@ tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0:
85168523
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35"
85178524
integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==
85188525

8526+
tslib@~2.1.0:
8527+
version "2.1.0"
8528+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
8529+
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==
8530+
85198531
tslint@6.1.1:
85208532
version "6.1.1"
85218533
resolved "https://registry.yarnpkg.com/tslint/-/tslint-6.1.1.tgz#ac03fbd17f85bfefaae348b353b25a88efe10cde"

0 commit comments

Comments
 (0)