-
Notifications
You must be signed in to change notification settings - Fork 10
/
isolation.test.tsx
67 lines (50 loc) · 1.81 KB
/
isolation.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
/**
* This test suite hooks into the componentDidUpdate method of components to
* assert that the components only update when they need to
*/
import React from 'react';
import * as testUtils from '../testUtils';
import App from './TaskListTest/App';
import { store } from '../..';
store.site = {
title: 'The task list site',
};
store.tasks = [
{
id: 1,
name: 'The first task in the isolation test',
done: false,
},
];
store.notifications = ['You have no unread messages at all'];
const props = {
onAppUpdate: jest.fn(),
onTaskListUpdate: jest.fn(),
onNotificationsUpdate: jest.fn(),
};
it('should handle isolation', () => {
const { getByText } = testUtils.renderStrict(<App {...props} />);
// should render the title
getByText('The task list site');
// should render a task
getByText('The first task in the isolation test');
// should render a notification
getByText('You have no unread messages at all');
// should re-render the App component but not the children
store.site.title = 'New and improved!';
expect(props.onAppUpdate).toHaveBeenCalledTimes(1);
expect(props.onTaskListUpdate).toHaveBeenCalledTimes(0);
expect(props.onNotificationsUpdate).toHaveBeenCalledTimes(0);
jest.resetAllMocks();
// should re-render the TaskList component only
if (store.tasks) store.tasks[0].done = true;
expect(props.onAppUpdate).toHaveBeenCalledTimes(0);
expect(props.onTaskListUpdate).toHaveBeenCalledTimes(1);
expect(props.onNotificationsUpdate).toHaveBeenCalledTimes(0);
jest.resetAllMocks();
// should re-render the Notifications component only
store.notifications[0] = 'You have a message now!';
expect(props.onAppUpdate).toHaveBeenCalledTimes(0);
expect(props.onTaskListUpdate).toHaveBeenCalledTimes(0);
expect(props.onNotificationsUpdate).toHaveBeenCalledTimes(1);
});