@@ -3,6 +3,7 @@ import { render } from "@testing-library/react-native";
33import {
44 View ,
55 TextInput ,
6+ Text ,
67} from "react-native" ;
78
89import { ElementAssertion } from "../../src/lib/ElementAssertion" ;
@@ -34,7 +35,7 @@ describe("[Unit] ElementAssertion.test.ts", () => {
3435 . toHaveMessage ( "Expected element <TextInput ... /> to be disabled." ) ;
3536 expect ( ( ) => test . not . toBeEnabled ( ) )
3637 . toThrowError ( AssertionError )
37- . toHaveMessage ( "Expected element <TextInput ... /> to NOT be enabled." ) ;
38+ . toHaveMessage ( "Expected element <TextInput ... /> NOT to be enabled." ) ;
3839 } ) ;
3940 } ) ;
4041 } ) ;
@@ -59,7 +60,7 @@ describe("[Unit] ElementAssertion.test.ts", () => {
5960 . toHaveMessage ( "Expected element <View ... /> to be enabled." ) ;
6061 expect ( ( ) => parent . not . toBeDisabled ( ) )
6162 . toThrowError ( AssertionError )
62- . toHaveMessage ( "Expected element <View ... /> to NOT be disabled." ) ;
63+ . toHaveMessage ( "Expected element <View ... /> NOT to be disabled." ) ;
6364 } ) ;
6465 } ) ;
6566
@@ -83,13 +84,13 @@ describe("[Unit] ElementAssertion.test.ts", () => {
8384 . toHaveMessage ( "Expected element <View ... /> to be disabled." ) ;
8485 expect ( ( ) => parent . not . toBeEnabled ( ) )
8586 . toThrowError ( AssertionError )
86- . toHaveMessage ( "Expected element <View ... /> to NOT be enabled." ) ;
87+ . toHaveMessage ( "Expected element <View ... /> NOT to be enabled." ) ;
8788 expect ( ( ) => child . toBeDisabled ( ) )
8889 . toThrowError ( AssertionError )
8990 . toHaveMessage ( "Expected element <View ... /> to be disabled." ) ;
9091 expect ( ( ) => child . not . toBeEnabled ( ) )
9192 . toThrowError ( AssertionError )
92- . toHaveMessage ( "Expected element <View ... /> to NOT be enabled." ) ;
93+ . toHaveMessage ( "Expected element <View ... /> NOT to be enabled." ) ;
9394 } ) ;
9495 } ) ;
9596 } ) ;
@@ -114,7 +115,7 @@ describe("[Unit] ElementAssertion.test.ts", () => {
114115 . toHaveMessage ( "Expected element <View ... /> to be enabled." ) ;
115116 expect ( ( ) => child . not . toBeDisabled ( ) )
116117 . toThrowError ( AssertionError )
117- . toHaveMessage ( "Expected element <View ... /> to NOT be disabled." ) ;
118+ . toHaveMessage ( "Expected element <View ... /> NOT to be disabled." ) ;
118119 } ) ;
119120
120121 it ( "returns error for parent element" , ( ) => {
@@ -124,9 +125,39 @@ describe("[Unit] ElementAssertion.test.ts", () => {
124125 . toHaveMessage ( "Expected element <View ... /> to be disabled." ) ;
125126 expect ( ( ) => parent . not . toBeEnabled ( ) )
126127 . toThrowError ( AssertionError )
127- . toHaveMessage ( "Expected element <View ... /> to NOT be enabled." ) ;
128+ . toHaveMessage ( "Expected element <View ... /> NOT to be enabled." ) ;
128129 } ) ;
129130 } ) ;
130131 } ) ;
131132 } ) ;
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+ } ) ;
132163} ) ;
0 commit comments