@@ -22,29 +22,30 @@ This library is a replacement for [Enzyme](http://airbnb.io/enzyme/).
22
22
``` jsx
23
23
import { render , fireEvent } from ' react-native-testing-library' ;
24
24
import { QuestionsBoard } from ' ../QuestionsBoard' ;
25
- import { Question } from ' ../Question' ;
26
25
27
- function setAnswer ( question , answer ) {
28
- fireEvent . changeText (question, answer) ;
29
- }
26
+ test ( ' form submits two answers ' , () => {
27
+ const allQuestions = [ ' q1 ' , ' q2 ' ] ;
28
+ const mockFn = jest . fn ();
30
29
31
- test (' should verify two questions' , () => {
32
- jest .spyOn (props, ' verifyQuestions' );
33
- const { getAllByA11yRole , getByText } = render (< QuestionsBoard {... props} / > );
34
- const allQuestions = getAllByA11yRole (' header' );
30
+ const { getAllByA11yLabel , getByText } = render (
31
+ < QuestionsBoard questions= {allQuestions} onSubmit= {mockFn} / >
32
+ );
35
33
36
- setAnswer (allQuestions[0 ], ' a1' );
37
- setAnswer (allQuestions[1 ], ' a2' );
34
+ const answerInputs = getAllByA11yLabel (' answer input' );
38
35
39
- fireEvent .press (getByText (' submit' ));
36
+ fireEvent .changeText (answerInputs[0 ], ' a1' );
37
+ fireEvent .changeText (answerInputs[1 ], ' a2' );
38
+ fireEvent .press (getByText (' Submit' ));
40
39
41
- expect (props . verifyQuestions ).toBeCalledWith ({
40
+ expect (mockFn ).toBeCalledWith ({
42
41
' 1' : { q: ' q1' , a: ' a1' },
43
42
' 2' : { q: ' q2' , a: ' a2' },
44
43
});
45
44
});
46
45
```
47
46
47
+ You can find the source of ` QuestionsBoard ` component and this example [ here] ( ../src/__tests__/questionsBoard.test.js ) .
48
+
48
49
## Installation
49
50
50
51
Open a Terminal in your project's folder and run:
0 commit comments