@@ -2,9 +2,7 @@ import React from 'react';
2
2
import 'jest-native/extend-expect' ;
3
3
import { Button , Image , Text , TextInput , TouchableHighlight } from 'react-native' ;
4
4
5
- import { cleanup , render , fireEvent , eventMap , NativeEvent , getEventHandlerName , wait } from '../' ;
6
-
7
- afterEach ( cleanup ) ;
5
+ import { render , fireEvent , eventMap , NativeEvent , getEventHandlerName , wait } from '../' ;
8
6
9
7
Object . keys ( eventMap ) . forEach ( key => {
10
8
const handlerName = getEventHandlerName ( key ) ;
@@ -15,14 +13,17 @@ Object.keys(eventMap).forEach(key => {
15
13
config . validTargets . forEach ( element => {
16
14
const spy = jest . fn ( ) ;
17
15
18
- const { getByTestId } = render (
16
+ const {
17
+ container : {
18
+ children : [ button ] ,
19
+ } ,
20
+ } = render (
19
21
React . createElement ( element , {
20
22
[ handlerName ] : spy ,
21
23
} ) ,
22
24
) ;
23
25
24
- const target = getByTestId ( 'ntl-container' ) . children [ 0 ] ;
25
- fireEvent [ key ] ( target ) ;
26
+ fireEvent [ key ] ( button ) ;
26
27
27
28
expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
28
29
} ) ;
@@ -31,9 +32,13 @@ Object.keys(eventMap).forEach(key => {
31
32
32
33
test ( 'onChange works' , ( ) => {
33
34
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' } } ) ;
37
42
expect ( handleChange ) . toHaveBeenCalledTimes ( 1 ) ;
38
43
} ) ;
39
44
@@ -75,10 +80,9 @@ test('assigns target properties', async () => {
75
80
76
81
test ( 'calling `fireEvent` directly works too' , ( ) => {
77
82
const handleEvent = jest . fn ( ) ;
78
- const { getByTestId } = render ( < Button onPress = { handleEvent } title = "test" /> ) ;
83
+ const { container } = render ( < Button onPress = { handleEvent } title = "test" /> ) ;
79
84
80
- const target = getByTestId ( 'ntl-container' ) . children [ 0 ] ;
81
- fireEvent ( target , new NativeEvent ( 'press' ) ) ;
85
+ fireEvent ( container . children [ 0 ] , new NativeEvent ( 'press' ) ) ;
82
86
expect ( handleEvent ) . toBeCalledTimes ( 1 ) ;
83
87
} ) ;
84
88
@@ -87,9 +91,13 @@ test('calling a custom event works as well', () => {
87
91
const onMyEvent = jest . fn ( ( { nativeEvent } ) => expect ( nativeEvent ) . toEqual ( { value : 'testing' } ) ) ;
88
92
const MyComponent = ( { onMyEvent } ) => < TextInput value = "test" onChange = { onMyEvent } /> ;
89
93
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 ) ) ;
93
101
94
102
expect ( onMyEvent ) . toHaveBeenCalledWith ( {
95
103
nativeEvent : { value : 'testing' } ,
0 commit comments