@@ -22,29 +22,30 @@ This library is a replacement for [Enzyme](http://airbnb.io/enzyme/).
2222``` jsx
2323import { render , fireEvent } from ' react-native-testing-library' ;
2424import { QuestionsBoard } from ' ../QuestionsBoard' ;
25- import { Question } from ' ../Question' ;
2625
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 ();
3029
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+ );
3533
36- setAnswer (allQuestions[0 ], ' a1' );
37- setAnswer (allQuestions[1 ], ' a2' );
34+ const answerInputs = getAllByA11yLabel (' answer input' );
3835
39- fireEvent .press (getByText (' submit' ));
36+ fireEvent .changeText (answerInputs[0 ], ' a1' );
37+ fireEvent .changeText (answerInputs[1 ], ' a2' );
38+ fireEvent .press (getByText (' Submit' ));
4039
41- expect (props . verifyQuestions ).toBeCalledWith ({
40+ expect (mockFn ).toBeCalledWith ({
4241 ' 1' : { q: ' q1' , a: ' a1' },
4342 ' 2' : { q: ' q2' , a: ' a2' },
4443 });
4544});
4645```
4746
47+ You can find the source of ` QuestionsBoard ` component and this example [ here] ( ../src/__tests__/questionsBoard.test.js ) .
48+
4849## Installation
4950
5051Open a Terminal in your project's folder and run:
0 commit comments