Skip to content

Commit 8eca0ef

Browse files
SimenBnhunzaker
authored andcommitted
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
1 parent 293fed8 commit 8eca0ef

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.internal.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ describe('ReactDOMSuspensePlaceholder', () => {
4343
}
4444
jest.advanceTimersByTime(ms);
4545
// 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(() => {});
4948
}
5049

5150
function Text(props) {

packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
6262
}
6363
jest.advanceTimersByTime(ms);
6464
// 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(() => {});
6867
}
6968

7069
function Text(props) {

packages/react/src/__tests__/ReactProfiler-test.internal.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,9 +2194,8 @@ describe('Profiler', () => {
21942194
function awaitableAdvanceTimers(ms) {
21952195
jest.advanceTimersByTime(ms);
21962196
// 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(() => {});
22002199
}
22012200

22022201
it('traces both the temporary placeholder and the finished render for an interaction', async () => {

packages/react/src/__tests__/ReactProfilerDOM-test.internal.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ let ReactCache;
1818
function initEnvForAsyncTesting() {
1919
// Boilerplate copied from ReactDOMRoot-test
2020
// 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
2522
global.requestAnimationFrame = function(cb) {
2623
return setTimeout(() => {
2724
cb(Date.now());
@@ -140,7 +137,7 @@ describe('ProfilerDOM', () => {
140137

141138
// Evaluate in an unwrapped callback,
142139
// Because trace/wrap won't decrement the count within the wrapped callback.
143-
setImmediate(() => {
140+
Promise.resolve().then(() => {
144141
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
145142
expect(
146143
onInteractionScheduledWorkCompleted,

0 commit comments

Comments
 (0)