@@ -4,12 +4,18 @@ import { IonButton } from '@ionic/react';
44
55import createContext from './_createContext' ;
66import mount from './_mount' ;
7+ import { merge } from 'lodash' ;
78
8- const parent = {
9- maxCount : 3 ,
10- minCount : 0 ,
11- value : [ 'x' , 'y' , 'z' ] ,
12- } ;
9+ const onChange = jest . fn ( ) ;
10+ const context = ( schema ?: { } ) =>
11+ createContext (
12+ merge ( { x : { type : Array , maxCount : 3 } , 'x.$' : String } , schema ) ,
13+ { onChange, model : { x : [ 'x' , 'y' , 'z' ] } } ,
14+ ) ;
15+
16+ beforeEach ( ( ) => {
17+ onChange . mockClear ( ) ;
18+ } ) ;
1319
1420test ( '<ListDelField> - works' , ( ) => {
1521 const element = < ListDelField name = "x.1" parent = { parent } /> ;
@@ -59,16 +65,9 @@ test('<ListDelField> - prevents onClick when limit reached', () => {
5965} ) ;
6066
6167test ( '<ListDelField> - correctly reacts on click' , ( ) => {
62- const onChange = jest . fn ( ) ;
63-
64- const element = (
65- < ListDelField name = "x.1" parent = { Object . assign ( { } , parent , { onChange } ) } />
66- ) ;
67- const wrapper = mount (
68- element ,
69- createContext ( { x : { type : Array } , 'x.$' : { type : String } } ) ,
70- ) ;
68+ const element = < ListDelField name = "x.1" /> ;
69+ const wrapper = mount ( element , context ( ) ) ;
7170
72- expect ( wrapper . find ( IonButton ) . simulate ( 'click' ) ) . toBeTruthy ( ) ;
73- expect ( onChange ) . toHaveBeenLastCalledWith ( [ 'x' , 'y ' ] ) ;
71+ expect ( wrapper . find ( IonButton ) . simulate ( 'click' ) ) . toBeTruthy ( ) ;
72+ expect ( onChange ) . toHaveBeenLastCalledWith ( 'x' , [ 'x' , 'z ' ] ) ;
7473} ) ;
0 commit comments