@@ -2,9 +2,7 @@ import React from 'react';
22import 'jest-native/extend-expect' ;
33import { Button , Image , Text , TextInput , TouchableHighlight } from 'react-native' ;
44
5- import { cleanup , render , fireEvent , eventMap , NativeEvent , getEventHandlerName , wait } from '../' ;
6-
7- afterEach ( cleanup ) ;
5+ import { render , fireEvent , eventMap , NativeEvent , getEventHandlerName , wait } from '../' ;
86
97Object . keys ( eventMap ) . forEach ( key => {
108 const handlerName = getEventHandlerName ( key ) ;
@@ -15,14 +13,17 @@ Object.keys(eventMap).forEach(key => {
1513 config . validTargets . forEach ( element => {
1614 const spy = jest . fn ( ) ;
1715
18- const { getByTestId } = render (
16+ const {
17+ container : {
18+ children : [ button ] ,
19+ } ,
20+ } = render (
1921 React . createElement ( element , {
2022 [ handlerName ] : spy ,
2123 } ) ,
2224 ) ;
2325
24- const target = getByTestId ( 'ntl-container' ) . children [ 0 ] ;
25- fireEvent [ key ] ( target ) ;
26+ fireEvent [ key ] ( button ) ;
2627
2728 expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
2829 } ) ;
@@ -31,9 +32,13 @@ Object.keys(eventMap).forEach(key => {
3132
3233test ( 'onChange works' , ( ) => {
3334 const handleChange = jest . fn ( ) ;
34- const { getByTestId } = render ( < TextInput onChange = { handleChange } /> ) ;
35- const target = getByTestId ( 'ntl-container' ) . children [ 0 ] ;
36- fireEvent . change ( target , { target : { value : 'a' } } ) ;
35+ const {
36+ container : {
37+ children : [ input ] ,
38+ } ,
39+ } = render ( < TextInput onChange = { handleChange } /> ) ;
40+
41+ fireEvent . change ( input , { target : { value : 'a' } } ) ;
3742 expect ( handleChange ) . toHaveBeenCalledTimes ( 1 ) ;
3843} ) ;
3944
@@ -75,10 +80,9 @@ test('assigns target properties', async () => {
7580
7681test ( 'calling `fireEvent` directly works too' , ( ) => {
7782 const handleEvent = jest . fn ( ) ;
78- const { getByTestId } = render ( < Button onPress = { handleEvent } title = "test" /> ) ;
83+ const { container } = render ( < Button onPress = { handleEvent } title = "test" /> ) ;
7984
80- const target = getByTestId ( 'ntl-container' ) . children [ 0 ] ;
81- fireEvent ( target , new NativeEvent ( 'press' ) ) ;
85+ fireEvent ( container . children [ 0 ] , new NativeEvent ( 'press' ) ) ;
8286 expect ( handleEvent ) . toBeCalledTimes ( 1 ) ;
8387} ) ;
8488
@@ -87,9 +91,13 @@ test('calling a custom event works as well', () => {
8791 const onMyEvent = jest . fn ( ( { nativeEvent } ) => expect ( nativeEvent ) . toEqual ( { value : 'testing' } ) ) ;
8892 const MyComponent = ( { onMyEvent } ) => < TextInput value = "test" onChange = { onMyEvent } /> ;
8993
90- const { getByTestId } = render ( < MyComponent onMyEvent = { onMyEvent } /> ) ;
91- const target = getByTestId ( 'ntl-container' ) . children [ 0 ] ;
92- fireEvent ( target , new NativeEvent ( 'myEvent' , event ) ) ;
94+ const {
95+ container : {
96+ children : [ input ] ,
97+ } ,
98+ } = render ( < MyComponent onMyEvent = { onMyEvent } /> ) ;
99+
100+ fireEvent ( input , new NativeEvent ( 'myEvent' , event ) ) ;
93101
94102 expect ( onMyEvent ) . toHaveBeenCalledWith ( {
95103 nativeEvent : { value : 'testing' } ,
0 commit comments