11import { actionValue } from "@mendix/piw-utils-internal" ;
22import { createElement } from "react" ;
33import { AppStateStatus } from "react-native" ;
4-
5- import { mount } from "enzyme" ;
4+ import { render } from "@testing-library/react-native" ;
65
76import { AppEvents , Props } from "../AppEvents" ;
87
@@ -54,31 +53,31 @@ describe("AppEvents", () => {
5453 } ) ;
5554
5655 it ( "does not render anything" , ( ) => {
57- const wrapper = mount ( < AppEvents { ...defaultProps } /> ) ;
58- expect ( wrapper ) . toMatchObject ( { } ) ;
56+ const { toJSON } = render ( < AppEvents { ...defaultProps } /> ) ;
57+ expect ( toJSON ( ) ) . toBeNull ( ) ;
5958 } ) ;
6059
6160 describe ( "with on load action" , ( ) => {
6261 it ( "executes the on load action" , ( ) => {
6362 const onLoadAction = actionValue ( ) ;
64- mount ( < AppEvents { ...defaultProps } onLoadAction = { onLoadAction } /> ) ;
63+ render ( < AppEvents { ...defaultProps } onLoadAction = { onLoadAction } /> ) ;
6564 expect ( onLoadAction . execute ) . toHaveBeenCalledTimes ( 1 ) ;
6665 } ) ;
6766 } ) ;
6867
6968 describe ( "with on resume action" , ( ) => {
7069 it ( "registers and unregisters an event listener" , ( ) => {
7170 const onResumeAction = actionValue ( ) ;
72- const wrapper = mount ( < AppEvents { ...defaultProps } onResumeAction = { onResumeAction } /> ) ;
71+ const { unmount } = render ( < AppEvents { ...defaultProps } onResumeAction = { onResumeAction } /> ) ;
7372
7473 expect ( appStateChangeHandler ) . toBeDefined ( ) ;
75- wrapper . unmount ( ) ;
74+ unmount ( ) ;
7675 expect ( appStateChangeHandler ) . toBeUndefined ( ) ;
7776 } ) ;
7877
7978 it ( "executes the on resume action" , ( ) => {
8079 const onResumeAction = actionValue ( ) ;
81- mount ( < AppEvents { ...defaultProps } onResumeAction = { onResumeAction } /> ) ;
80+ render ( < AppEvents { ...defaultProps } onResumeAction = { onResumeAction } /> ) ;
8281
8382 appStateChangeHandler ! ( "background" ) ;
8483 appStateChangeHandler ! ( "active" ) ;
@@ -87,7 +86,7 @@ describe("AppEvents", () => {
8786
8887 it ( "does not execute the on resume action when the app state hasn't changed" , ( ) => {
8988 const onResumeAction = actionValue ( ) ;
90- mount ( < AppEvents { ...defaultProps } onResumeAction = { onResumeAction } /> ) ;
89+ render ( < AppEvents { ...defaultProps } onResumeAction = { onResumeAction } /> ) ;
9190
9291 appStateChangeHandler ! ( "active" ) ;
9392 appStateChangeHandler ! ( "active" ) ;
@@ -98,7 +97,7 @@ describe("AppEvents", () => {
9897 const dateNowSpy = jest . spyOn ( Date , "now" ) . mockReturnValue ( 0 ) ;
9998
10099 const onResumeAction = actionValue ( ) ;
101- mount ( < AppEvents { ...defaultProps } onResumeAction = { onResumeAction } onResumeTimeout = { 5 } /> ) ;
100+ render ( < AppEvents { ...defaultProps } onResumeAction = { onResumeAction } onResumeTimeout = { 5 } /> ) ;
102101
103102 dateNowSpy . mockReturnValue ( 4000 ) ;
104103 appStateChangeHandler ! ( "background" ) ;
@@ -117,17 +116,17 @@ describe("AppEvents", () => {
117116 describe ( "with on online action" , ( ) => {
118117 it ( "registers and unregisters an event listener" , async ( ) => {
119118 const onOnlineAction = actionValue ( ) ;
120- const wrapper = mount ( < AppEvents { ...defaultProps } onOnlineAction = { onOnlineAction } /> ) ;
119+ const { unmount } = render ( < AppEvents { ...defaultProps } onOnlineAction = { onOnlineAction } /> ) ;
121120 await flushMicrotasksQueue ( ) ;
122121
123122 expect ( connectionChangeHandler ) . toBeDefined ( ) ;
124- wrapper . unmount ( ) ;
123+ unmount ( ) ;
125124 expect ( connectionChangeHandler ) . toBeUndefined ( ) ;
126125 } ) ;
127126
128127 it ( "executes the on online action" , async ( ) => {
129128 const onOnlineAction = actionValue ( ) ;
130- mount ( < AppEvents { ...defaultProps } onOnlineAction = { onOnlineAction } /> ) ;
129+ render ( < AppEvents { ...defaultProps } onOnlineAction = { onOnlineAction } /> ) ;
131130 await flushMicrotasksQueue ( ) ;
132131
133132 connectionChangeHandler ! ( { isConnected : false } ) ;
@@ -139,7 +138,7 @@ describe("AppEvents", () => {
139138 const dateNowSpy = jest . spyOn ( Date , "now" ) . mockReturnValue ( 0 ) ;
140139
141140 const onOnlineAction = actionValue ( ) ;
142- mount ( < AppEvents { ...defaultProps } onOnlineAction = { onOnlineAction } onOnlineTimeout = { 5 } /> ) ;
141+ render ( < AppEvents { ...defaultProps } onOnlineAction = { onOnlineAction } onOnlineTimeout = { 5 } /> ) ;
143142 await flushMicrotasksQueue ( ) ;
144143
145144 dateNowSpy . mockReturnValue ( 4000 ) ;
@@ -157,7 +156,7 @@ describe("AppEvents", () => {
157156
158157 it ( "does not execute the on online action if the connection state didn't change" , async ( ) => {
159158 const onOnlineAction = actionValue ( ) ;
160- mount ( < AppEvents { ...defaultProps } onOnlineAction = { onOnlineAction } /> ) ;
159+ render ( < AppEvents { ...defaultProps } onOnlineAction = { onOnlineAction } /> ) ;
161160 await flushMicrotasksQueue ( ) ;
162161
163162 connectionChangeHandler ! ( { isConnected : true } ) ;
@@ -178,7 +177,7 @@ describe("AppEvents", () => {
178177
179178 it ( "executes the on timeout action once after the timeout has passed" , ( ) => {
180179 const onTimeoutAction = actionValue ( ) ;
181- mount ( < AppEvents { ...defaultProps } onTimeoutAction = { onTimeoutAction } /> ) ;
180+ render ( < AppEvents { ...defaultProps } onTimeoutAction = { onTimeoutAction } /> ) ;
182181
183182 expect ( onTimeoutAction . execute ) . toHaveBeenCalledTimes ( 0 ) ;
184183 jest . advanceTimersByTime ( 30000 ) ;
@@ -189,16 +188,16 @@ describe("AppEvents", () => {
189188
190189 it ( "does not execute the on timeout action after the component has been unmounted" , ( ) => {
191190 const onTimeoutAction = actionValue ( ) ;
192- const wrapper = mount ( < AppEvents { ...defaultProps } onTimeoutAction = { onTimeoutAction } /> ) ;
191+ const { unmount } = render ( < AppEvents { ...defaultProps } onTimeoutAction = { onTimeoutAction } /> ) ;
193192 jest . advanceTimersByTime ( 15000 ) ;
194- wrapper . unmount ( ) ;
193+ unmount ( ) ;
195194 jest . advanceTimersByTime ( 15000 ) ;
196195 expect ( onTimeoutAction . execute ) . toHaveBeenCalledTimes ( 0 ) ;
197196 } ) ;
198197
199198 it ( "executes the interval on timeout action after every interval" , ( ) => {
200199 const onTimeoutAction = actionValue ( ) ;
201- mount ( < AppEvents { ...defaultProps } onTimeoutAction = { onTimeoutAction } timerType = { "interval" } /> ) ;
200+ render ( < AppEvents { ...defaultProps } onTimeoutAction = { onTimeoutAction } timerType = { "interval" } /> ) ;
202201
203202 expect ( onTimeoutAction . execute ) . toHaveBeenCalledTimes ( 0 ) ;
204203 jest . advanceTimersByTime ( 30000 ) ;
@@ -209,20 +208,20 @@ describe("AppEvents", () => {
209208
210209 it ( "does not execute the interval on timeout action after the component has been unmounted" , ( ) => {
211210 const onTimeoutAction = actionValue ( ) ;
212- const wrapper = mount (
211+ const { unmount } = render (
213212 < AppEvents { ...defaultProps } onTimeoutAction = { onTimeoutAction } timerType = { "interval" } />
214213 ) ;
215214
216215 jest . advanceTimersByTime ( 30000 ) ;
217216 expect ( onTimeoutAction . execute ) . toHaveBeenCalledTimes ( 1 ) ;
218- wrapper . unmount ( ) ;
217+ unmount ( ) ;
219218 jest . advanceTimersByTime ( 30000 ) ;
220219 expect ( onTimeoutAction . execute ) . toHaveBeenCalledTimes ( 1 ) ;
221220 } ) ;
222221
223222 it ( "does not execute the interval on timeout action when it is already executing" , ( ) => {
224223 const onTimeoutAction = actionValue ( true , true ) ;
225- mount ( < AppEvents { ...defaultProps } onTimeoutAction = { onTimeoutAction } timerType = { "interval" } /> ) ;
224+ render ( < AppEvents { ...defaultProps } onTimeoutAction = { onTimeoutAction } timerType = { "interval" } /> ) ;
226225
227226 jest . advanceTimersByTime ( 30000 ) ;
228227 expect ( onTimeoutAction . execute ) . not . toHaveBeenCalled ( ) ;
0 commit comments