-
Notifications
You must be signed in to change notification settings - Fork 263
/
TodoList.test.js
57 lines (47 loc) 路 1.6 KB
/
TodoList.test.js
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
import React from 'react';
import { Provider } from 'react-redux';
import { fireEvent, render } from 'react-native-testing-library';
import configureStore from '../store';
import TodoList from './TodoList';
describe('Application test', () => {
test('it should execute with a store with 4 elements', () => {
const initialState = {
todos: [
{ id: 1, text: 'Sing something', date: new Date() },
{ id: 2, text: 'Dance something', date: new Date() },
{ id: 3, text: 'Sleep something', date: new Date() },
{ id: 4, text: 'Sleep something', date: new Date() },
],
};
const store = configureStore(initialState);
const component = (
<Provider store={store}>
<TodoList />
</Provider>
);
const { getAllByText } = render(component);
const todoElems = getAllByText(/something/i);
expect(todoElems.length).toEqual(4);
});
test('should execute with 2 elements and end up with 1 after delete', () => {
const initialState = {
todos: [
{ id: 1, text: 'Sing something', date: new Date() },
{ id: 2, text: 'Dance something', date: new Date() },
],
};
const store = configureStore(initialState);
const component = (
<Provider store={store}>
<TodoList />
</Provider>
);
const { getAllByText } = render(component);
const todoElems = getAllByText(/something/i);
expect(todoElems.length).toBe(2);
const buttons = getAllByText('Delete');
expect(buttons.length).toBe(2);
fireEvent.press(buttons[0]);
expect(getAllByText('Delete').length).toBe(1);
});
});