@@ -3,6 +3,7 @@ import { render } from "@testing-library/react-native";
3
3
import {
4
4
View ,
5
5
TextInput ,
6
+ Text ,
6
7
} from "react-native" ;
7
8
8
9
import { ElementAssertion } from "../../src/lib/ElementAssertion" ;
@@ -34,7 +35,7 @@ describe("[Unit] ElementAssertion.test.ts", () => {
34
35
. toHaveMessage ( "Expected element <TextInput ... /> to be disabled." ) ;
35
36
expect ( ( ) => test . not . toBeEnabled ( ) )
36
37
. toThrowError ( AssertionError )
37
- . toHaveMessage ( "Expected element <TextInput ... /> to NOT be enabled." ) ;
38
+ . toHaveMessage ( "Expected element <TextInput ... /> NOT to be enabled." ) ;
38
39
} ) ;
39
40
} ) ;
40
41
} ) ;
@@ -59,7 +60,7 @@ describe("[Unit] ElementAssertion.test.ts", () => {
59
60
. toHaveMessage ( "Expected element <View ... /> to be enabled." ) ;
60
61
expect ( ( ) => parent . not . toBeDisabled ( ) )
61
62
. toThrowError ( AssertionError )
62
- . toHaveMessage ( "Expected element <View ... /> to NOT be disabled." ) ;
63
+ . toHaveMessage ( "Expected element <View ... /> NOT to be disabled." ) ;
63
64
} ) ;
64
65
} ) ;
65
66
@@ -83,13 +84,13 @@ describe("[Unit] ElementAssertion.test.ts", () => {
83
84
. toHaveMessage ( "Expected element <View ... /> to be disabled." ) ;
84
85
expect ( ( ) => parent . not . toBeEnabled ( ) )
85
86
. toThrowError ( AssertionError )
86
- . toHaveMessage ( "Expected element <View ... /> to NOT be enabled." ) ;
87
+ . toHaveMessage ( "Expected element <View ... /> NOT to be enabled." ) ;
87
88
expect ( ( ) => child . toBeDisabled ( ) )
88
89
. toThrowError ( AssertionError )
89
90
. toHaveMessage ( "Expected element <View ... /> to be disabled." ) ;
90
91
expect ( ( ) => child . not . toBeEnabled ( ) )
91
92
. toThrowError ( AssertionError )
92
- . toHaveMessage ( "Expected element <View ... /> to NOT be enabled." ) ;
93
+ . toHaveMessage ( "Expected element <View ... /> NOT to be enabled." ) ;
93
94
} ) ;
94
95
} ) ;
95
96
} ) ;
@@ -114,7 +115,7 @@ describe("[Unit] ElementAssertion.test.ts", () => {
114
115
. toHaveMessage ( "Expected element <View ... /> to be enabled." ) ;
115
116
expect ( ( ) => child . not . toBeDisabled ( ) )
116
117
. toThrowError ( AssertionError )
117
- . toHaveMessage ( "Expected element <View ... /> to NOT be disabled." ) ;
118
+ . toHaveMessage ( "Expected element <View ... /> NOT to be disabled." ) ;
118
119
} ) ;
119
120
120
121
it ( "returns error for parent element" , ( ) => {
@@ -124,9 +125,39 @@ describe("[Unit] ElementAssertion.test.ts", () => {
124
125
. toHaveMessage ( "Expected element <View ... /> to be disabled." ) ;
125
126
expect ( ( ) => parent . not . toBeEnabled ( ) )
126
127
. toThrowError ( AssertionError )
127
- . toHaveMessage ( "Expected element <View ... /> to NOT be enabled." ) ;
128
+ . toHaveMessage ( "Expected element <View ... /> NOT to be enabled." ) ;
128
129
} ) ;
129
130
} ) ;
130
131
} ) ;
131
132
} ) ;
133
+
134
+ describe ( ".toBeEmpty" , ( ) => {
135
+ context ( "when the element is empty" , ( ) => {
136
+ it ( "returns the assertion instance" , ( ) => {
137
+ const element = render ( < View testID = "id" /> ) ;
138
+ const test = new ElementAssertion ( element . getByTestId ( "id" ) ) ;
139
+
140
+ expect ( test . toBeEmpty ( ) ) . toBe ( test ) ;
141
+ expect ( ( ) => test . not . toBeEmpty ( ) )
142
+ . toThrowError ( AssertionError )
143
+ . toHaveMessage ( "Expected element <View ... /> NOT to be empty." ) ;
144
+ } ) ;
145
+ } ) ;
146
+
147
+ context ( "when the element is NOT empty" , ( ) => {
148
+ it ( "throws an error" , ( ) => {
149
+ const element = render (
150
+ < View testID = "id" >
151
+ < Text > { "Not empty" } </ Text >
152
+ </ View > ,
153
+ ) ;
154
+ const test = new ElementAssertion ( element . getByTestId ( "id" ) ) ;
155
+
156
+ expect ( test . not . toBeEmpty ( ) ) . toBeEqual ( test ) ;
157
+ expect ( ( ) => test . toBeEmpty ( ) )
158
+ . toThrowError ( AssertionError )
159
+ . toHaveMessage ( "Expected element <View ... /> to be empty." ) ;
160
+ } ) ;
161
+ } ) ;
162
+ } ) ;
132
163
} ) ;
0 commit comments