Skip to content

Commit f45177e

Browse files
committed
use enum-like object for timer modes
1 parent 08351f7 commit f45177e

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/__tests__/timerUtils.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { setTimeout } from '../helpers/getTimerFuncs';
22

3-
const FakeTimerTypes = [
4-
'default',
5-
'legacy',
6-
// 'modern', // broken for now
7-
];
3+
const TimerMode = {
4+
Default: 'default',
5+
Legacy: 'legacy',
6+
Modern: 'modern', // broken for now
7+
};
88

99
function setupFakeTimers(fakeTimerType) {
1010
switch (fakeTimerType) {
11-
case 'legacy':
12-
case 'modern': {
11+
case TimerMode.Legacy:
12+
case TimerMode.Modern: {
1313
jest.useFakeTimers(fakeTimerType);
1414
break;
1515
}
16-
case 'default':
16+
case TimerMode.Default:
1717
default: {
1818
jest.useFakeTimers();
1919
}
@@ -24,4 +24,4 @@ async function sleep(ms) {
2424
return new Promise((resolve) => setTimeout(resolve, ms));
2525
}
2626

27-
export { FakeTimerTypes, setupFakeTimers, sleep };
27+
export { TimerMode, setupFakeTimers, sleep };

src/__tests__/waitFor.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as React from 'react';
33
import { Text, TouchableOpacity, View } from 'react-native';
44
import { fireEvent, render, waitFor } from '..';
5-
import { FakeTimerTypes, setupFakeTimers, sleep } from './timerUtils';
5+
import { TimerMode, setupFakeTimers, sleep } from './timerUtils';
66

77
class Banana extends React.Component<any> {
88
changeFresh = () => {
@@ -80,7 +80,7 @@ test('waits for element with custom interval', async () => {
8080
expect(mockFn).toHaveBeenCalledTimes(3);
8181
});
8282

83-
test.each(FakeTimerTypes)(
83+
test.each([TimerMode.Default, TimerMode.Legacy])(
8484
'waits for element until it stops throwing using %s fake timers',
8585
async (fakeTimerType) => {
8686
setupFakeTimers(fakeTimerType);
@@ -96,7 +96,7 @@ test.each(FakeTimerTypes)(
9696
}
9797
);
9898

99-
test.each(FakeTimerTypes)(
99+
test.each([TimerMode.Default, TimerMode.Legacy])(
100100
'waits for assertion until timeout is met with %s fake timers',
101101
async (fakeTimerType) => {
102102
setupFakeTimers(fakeTimerType);
@@ -115,7 +115,7 @@ test.each(FakeTimerTypes)(
115115
}
116116
);
117117

118-
test.each(FakeTimerTypes)(
118+
test.each([TimerMode.Default, TimerMode.Legacy])(
119119
'awaiting something that succeeds before timeout works with %s fake timers',
120120
async (fakeTimerType) => {
121121
setupFakeTimers(fakeTimerType);
@@ -142,7 +142,7 @@ test.each(FakeTimerTypes)(
142142
// it is included to show that the previous approach of faking modern timers still works
143143
// the gotcha is that the try catch will fail to catch the final error, which is why we need to stop throwing
144144
test('non-awaited approach is not affected by fake modern timers', async () => {
145-
jest.useFakeTimers('modern');
145+
setupFakeTimers(TimerMode.Modern);
146146

147147
let calls = 0;
148148
const mockFn = jest.fn(() => {

0 commit comments

Comments
 (0)