diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md
index 41c5ba0a0..9b11eddf3 100644
--- a/docs/GettingStarted.md
+++ b/docs/GettingStarted.md
@@ -22,29 +22,30 @@ This library is a replacement for [Enzyme](http://airbnb.io/enzyme/).
```jsx
import { render, fireEvent } from 'react-native-testing-library';
import { QuestionsBoard } from '../QuestionsBoard';
-import { Question } from '../Question';
-function setAnswer(question, answer) {
- fireEvent.changeText(question, answer);
-}
+test('form submits two answers', () => {
+ const allQuestions = ['q1', 'q2'];
+ const mockFn = jest.fn();
-test('should verify two questions', () => {
- jest.spyOn(props, 'verifyQuestions');
- const { getAllByA11yRole, getByText } = render();
- const allQuestions = getAllByA11yRole('header');
+ const { getAllByA11yLabel, getByText } = render(
+
+ );
- setAnswer(allQuestions[0], 'a1');
- setAnswer(allQuestions[1], 'a2');
+ const answerInputs = getAllByA11yLabel('answer input');
- fireEvent.press(getByText('submit'));
+ fireEvent.changeText(answerInputs[0], 'a1');
+ fireEvent.changeText(answerInputs[1], 'a2');
+ fireEvent.press(getByText('Submit'));
- expect(props.verifyQuestions).toBeCalledWith({
+ expect(mockFn).toBeCalledWith({
'1': { q: 'q1', a: 'a1' },
'2': { q: 'q2', a: 'a2' },
});
});
```
+You can find the source of `QuestionsBoard` component and this example [here](../src/__tests__/questionsBoard.test.js).
+
## Installation
Open a Terminal in your project's folder and run:
diff --git a/src/__tests__/questionsBoard.test.js b/src/__tests__/questionsBoard.test.js
new file mode 100644
index 000000000..6bef268df
--- /dev/null
+++ b/src/__tests__/questionsBoard.test.js
@@ -0,0 +1,58 @@
+// @flow
+import React from 'react';
+import {
+ View,
+ TouchableOpacity,
+ Text,
+ ScrollView,
+ TextInput,
+} from 'react-native';
+import { render, fireEvent } from '..';
+
+function QuestionsBoard({ questions, onSubmit }) {
+ const [data, setData] = React.useState({});
+
+ return (
+
+ {questions.map((q, index) => {
+ return (
+
+ {q}
+ {
+ setData(state => ({
+ ...state,
+ [index + 1]: { q, a: text },
+ }));
+ }}
+ />
+
+ );
+ })}
+ onSubmit(data)}>
+ Submit
+
+
+ );
+}
+
+test('form submits two answers', () => {
+ const allQuestions = ['q1', 'q2'];
+ const mockFn = jest.fn();
+
+ const { getAllByA11yLabel, getByText } = render(
+
+ );
+
+ const answerInputs = getAllByA11yLabel('answer input');
+
+ fireEvent.changeText(answerInputs[0], 'a1');
+ fireEvent.changeText(answerInputs[1], 'a2');
+ fireEvent.press(getByText('Submit'));
+
+ expect(mockFn).toBeCalledWith({
+ '1': { q: 'q1', a: 'a1' },
+ '2': { q: 'q2', a: 'a2' },
+ });
+});