Skip to content

Commit 2bb868c

Browse files
chiciocortinico
authored andcommitted
fix: migrate LogBoxData-test to jest modern timers
1 parent aefe0f5 commit 2bb868c

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

packages/react-native/Libraries/LogBox/Data/__tests__/LogBoxData-test.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
'use strict';
1212

13-
// TODO(legacy-fake-timers): Fix these tests to work with modern timers.
14-
jest.useFakeTimers({legacyFakeTimers: true});
15-
1613
jest.mock('../../../Core/Devtools/parseErrorStack', () => {
1714
return {__esModule: true, default: jest.fn(() => [])};
1815
});
@@ -144,16 +141,17 @@ const addSyntaxError = (options: $FlowFixMe) => {
144141
);
145142
};
146143

147-
beforeEach(() => {
148-
jest.resetModules();
149-
});
150-
151144
const flushToObservers = () => {
152145
// Observer updates are debounced and need to advance timers to flush.
153146
jest.runOnlyPendingTimers();
154147
};
155148

156149
describe('LogBoxData', () => {
150+
beforeEach(() => {
151+
jest.useFakeTimers();
152+
jest.resetModules();
153+
});
154+
157155
it('adds and dismisses logs', () => {
158156
addLogs(['A']);
159157
addSoftErrors(['B']);
@@ -590,9 +588,13 @@ describe('LogBoxData', () => {
590588
expect(observer.mock.calls.length).toBe(1);
591589

592590
addLogs(['A']);
591+
flushToObservers();
593592
addSoftErrors(['B']);
593+
flushToObservers();
594594
addFatalErrors(['C']);
595+
flushToObservers();
595596
addSyntaxError();
597+
flushToObservers();
596598
expect(observer.mock.calls.length).toBe(5);
597599

598600
LogBoxData.clearWarnings();
@@ -610,9 +612,13 @@ describe('LogBoxData', () => {
610612
expect(observer.mock.calls.length).toBe(1);
611613

612614
addLogs(['A']);
615+
flushToObservers();
613616
addSoftErrors(['B']);
617+
flushToObservers();
614618
addFatalErrors(['C']);
619+
flushToObservers();
615620
addSyntaxError();
621+
flushToObservers();
616622
expect(observer.mock.calls.length).toBe(5);
617623

618624
LogBoxData.clearErrors();
@@ -854,4 +860,8 @@ describe('LogBoxData', () => {
854860
expect(Array.from(observerAfter.mock.calls[0][0].logs).length).toBe(0);
855861
});
856862
});
863+
864+
afterEach(() => {
865+
jest.useRealTimers();
866+
});
857867
});

0 commit comments

Comments
 (0)