forked from callstack/react-native-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddTodo.test.js
40 lines (32 loc) · 1.02 KB
/
AddTodo.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
import React from 'react';
import { Provider } from 'react-redux';
import { fireEvent, render } from 'react-native-testing-library';
import configureStore from '../store';
import AddTodo from './AddTodo';
describe('Application test', () => {
test('adds a new test when entry has been included', () => {
const store = configureStore();
const component = (
<Provider store={store}>
<AddTodo />
</Provider>
);
const { getByPlaceholder, getByText } = render(component);
const input = getByPlaceholder(/repository/i);
expect(input).toBeTruthy();
const textToEnter = 'This is a random element';
fireEvent.changeText(input, textToEnter);
fireEvent.press(getByText('Submit form'));
const todosState = store.getState().todos;
expect(todosState.length).toEqual(1);
expect(todosState).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: 1,
text: textToEnter,
date: expect.any(Date),
}),
])
);
});
});