Skip to content

Commit 1f6bc24

Browse files
authored
docs: fix readme example (#288)
1 parent 68bfe63 commit 1f6bc24

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,30 @@ This library is a replacement for [Enzyme](http://airbnb.io/enzyme/). It is test
3636
```jsx
3737
import { render, fireEvent } from 'react-native-testing-library';
3838
import { QuestionsBoard } from '../QuestionsBoard';
39-
import { Question } from '../Question';
4039

41-
function setAnswer(question, answer) {
42-
fireEvent.changeText(question, answer);
43-
}
40+
test('form submits two answers', () => {
41+
const allQuestions = ['q1', 'q2'];
42+
const mockFn = jest.fn();
4443

45-
test('should verify two questions', () => {
46-
const { getAllByA11yRole, getByText } = render(<QuestionsBoard {...props} />);
47-
const allQuestions = getAllByA11yRole('header');
44+
const { getAllByA11yLabel, getByText } = render(
45+
<QuestionsBoard questions={allQuestions} onSubmit={mockFn} />
46+
);
4847

49-
setAnswer(allQuestions[0], 'a1');
50-
setAnswer(allQuestions[1], 'a2');
48+
const answerInputs = getAllByA11yLabel('answer input');
5149

52-
fireEvent.press(getByText('submit'));
50+
fireEvent.changeText(answerInputs[0], 'a1');
51+
fireEvent.changeText(answerInputs[1], 'a2');
52+
fireEvent.press(getByText('Submit'));
5353

54-
expect(props.verifyQuestions).toBeCalledWith({
54+
expect(mockFn).toBeCalledWith({
5555
'1': { q: 'q1', a: 'a1' },
5656
'2': { q: 'q2', a: 'a2' },
5757
});
5858
});
5959
```
6060

61+
You can find the source of `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/questionsBoard.test.js).
62+
6163
## Installation
6264

6365
Open a Terminal in your project's folder and run:

0 commit comments

Comments
 (0)