chore(tests): don't rely on jest fake timers scheduling real timers (#14003)
* chore: don't rely on jest fake timers scheduling real timers * re-add one part not working with Jest 23
Simen Bekkhus committed
Nov 3, 2018 at 08:54 UTC
8eca0eff87bcb1046b7ef318e8f3d0c7ea2613c6
4 files changed
+8
-14
packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.internal.js
+2
-3
@@ -43,9 +43,8 @@ describe('ReactDOMSuspensePlaceholder', () => {
43
}
44
jest.advanceTimersByTime(ms);
45
// Wait until the end of the current tick
46
- return new Promise(resolve => {
47
- setImmediate(resolve);
48
- });
46
+ // We cannot use a timer since we're faking them
47
+ return Promise.resolve().then(() => {});
48
}
49
50
function Text(props) {
packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js
+2
-3
@@ -62,9 +62,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
62
}
63
jest.advanceTimersByTime(ms);
64
// Wait until the end of the current tick
65
- return new Promise(resolve => {
66
- setImmediate(resolve);
67
- });
65
+ // We cannot use a timer since we're faking them
66
+ return Promise.resolve().then(() => {});
67
}
68
69
function Text(props) {
packages/react/src/__tests__/ReactProfiler-test.internal.js
+2
-3
@@ -2194,9 +2194,8 @@ describe('Profiler', () => {
2194
function awaitableAdvanceTimers(ms) {
2195
jest.advanceTimersByTime(ms);
2196
// Wait until the end of the current tick
2197
- return new Promise(resolve => {
2198
- setImmediate(resolve);
2199
- });
2197
+ // We cannot use a timer since we're faking them
2198
+ return Promise.resolve().then(() => {});
2199
}
2200
2201
it('traces both the temporary placeholder and the finished render for an interaction', async () => {
packages/react/src/__tests__/ReactProfilerDOM-test.internal.js
+2
-5
@@ -18,10 +18,7 @@ let ReactCache;
18
function initEnvForAsyncTesting() {
19
// Boilerplate copied from ReactDOMRoot-test
20
// TODO pull this into helper method, reduce repetition.
21
- const originalDateNow = Date.now;
22
- global.Date.now = function() {
23
- return originalDateNow();
24
- };
21
+ // TODO remove `requestAnimationFrame` when upgrading to Jest 24 with Lolex
22
global.requestAnimationFrame = function(cb) {
23
return setTimeout(() => {
24
cb(Date.now());
@@ -140,7 +137,7 @@ describe('ProfilerDOM', () => {
137
138
// Evaluate in an unwrapped callback,
139
// Because trace/wrap won't decrement the count within the wrapped callback.
143
- setImmediate(() => {
140
+ Promise.resolve().then(() => {
141
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
142
expect(
143
onInteractionScheduledWorkCompleted,