-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.test.tsx
75 lines (59 loc) · 1.93 KB
/
App.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { TEST_DEFAULT_DATE } from '#testing/constants';
import { renderWithProviders } from '#testing/render';
import { screen } from '@testing-library/react-native';
import React from 'react';
import { Text, View } from 'react-native';
import App from './App';
it('finds rendered text', () => {
renderWithProviders(<App />);
expect(
screen.getByText(/Welcome to the Joconde Bootstrap App/),
).toBeOnTheScreen();
});
test('works with fake timers', async () => {
let loading = true;
let data: string | undefined = undefined;
jest.setSystemTime(Date.now());
const Suspending = () => {
// eslint-disable-next-line jest/no-conditional-in-test
if (loading)
throw Promise.resolve('result').then((result) => {
data = result;
loading = false;
});
return <Text>{data}</Text>;
};
const screen = renderWithProviders(
<View>
<React.Suspense fallback={<Text>Loading</Text>}>
<Suspending />
</React.Suspense>
</View>,
);
expect(await screen.findByText('result')).toBeOnTheScreen();
});
it('uses fake timers', () => {
const callback = jest.fn();
setTimeout(callback, 1000);
expect(callback).not.toHaveBeenCalled();
jest.advanceTimersByTime(1000);
expect(callback).toHaveBeenCalledWith();
});
describe('date is mocked', () => {
it('uses a mocked date', () => {
expect(new Date(Date.now()).toISOString()).toBe(TEST_DEFAULT_DATE);
});
it('allows overriding the mock in a given test', () => {
jest.setSystemTime(1244);
expect(Date.now()).toBe(1244);
});
it("and then it's back to the global mock in the next test", () => {
expect(new Date(Date.now()).toISOString()).toBe(TEST_DEFAULT_DATE);
});
});
describe('timezone is mocked', () => {
it('is in the Europe/Paris timezone', () => {
// On our computers this is obviously true, but in the CI it would fail without the mock
expect(new Date().getTimezoneOffset()).toBe(-60);
});
});