Skip to content

Commit c9b55ba

Browse files
committed
mock Performance for node 14
1 parent 62f6ad8 commit c9b55ba

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

test/invalidation.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default typeof AbortController === "undefined" ? mockit : it;
1+
export default typeof AbortController === "undefined" || typeof performance === "undefined" ? mockit : it;
22

33
function mockit(description, run) {
44
return it(description, withMock(run));
@@ -13,18 +13,29 @@ mockit.only = (description, run) => {
1313
};
1414

1515
class MockAbortController {
16+
constructor() {
17+
this.signal = {aborted: false};
18+
}
1619
abort() {
17-
// mock noop for node 14
20+
this.signal.aborted = true;
21+
}
22+
}
23+
24+
class MockPerformance {
25+
static now() {
26+
return Date.now();
1827
}
1928
}
2029

2130
function withMock(run) {
2231
return async () => {
2332
global.AbortController = MockAbortController;
33+
global.performance = MockPerformance;
2434
try {
2535
return await run();
2636
} finally {
2737
delete global.AbortController;
38+
delete global.performance;
2839
}
2940
};
3041
}

0 commit comments

Comments
 (0)