@@ -66,17 +66,18 @@ describe('Yup', function() {
66
66
} ) ;
67
67
68
68
it ( 'should getIn correctly' , async ( ) => {
69
- var num = number ( ) ,
70
- inst = object ( ) . shape ( {
71
- num : number ( ) . max ( 4 ) ,
72
-
73
- nested : object ( ) . shape ( {
74
- arr : array ( ) . of ( object ( ) . shape ( { 'num-1' : num } ) ) ,
75
- } ) ,
76
- } ) ;
69
+ let num = number ( ) ;
70
+ let shape = object ( { 'num-1' : num } ) ;
71
+ let inst = object ( {
72
+ num : number ( ) . max ( 4 ) ,
73
+
74
+ nested : object ( {
75
+ arr : array ( ) . of ( shape ) ,
76
+ } ) ,
77
+ } ) ;
77
78
78
79
const value = { nested : { arr : [ { } , { 'num-1' : 2 } ] } } ;
79
- const { schema, parent, parentPath } = getIn (
80
+ let { schema, parent, parentPath } = getIn (
80
81
inst ,
81
82
'nested.arr[1].num-1' ,
82
83
value ,
@@ -87,21 +88,50 @@ describe('Yup', function() {
87
88
expect ( parent ) . to . equal ( value . nested . arr [ 1 ] ) ;
88
89
} ) ;
89
90
91
+ it ( 'should getIn array correctly' , async ( ) => {
92
+ let num = number ( ) ;
93
+ let shape = object ( { 'num-1' : num } ) ;
94
+ let inst = object ( {
95
+ num : number ( ) . max ( 4 ) ,
96
+
97
+ nested : object ( {
98
+ arr : array ( ) . of ( shape ) ,
99
+ } ) ,
100
+ } ) ;
101
+
102
+ const value = {
103
+ nested : {
104
+ arr : [ { } , { 'num-1' : 2 } ] ,
105
+ } ,
106
+ } ;
107
+
108
+ const { schema, parent, parentPath } = getIn ( inst , 'nested.arr[1]' , value ) ;
109
+
110
+ console . log ( parentPath ) ;
111
+ expect ( schema ) . to . equal ( shape ) ;
112
+ expect ( parentPath ) . to . equal ( '1' ) ;
113
+ expect ( parent ) . to . equal ( value . nested . arr ) ;
114
+ } ) ;
115
+
90
116
it ( 'should REACH correctly' , async ( ) => {
91
- var num = number ( ) ,
92
- inst = object ( ) . shape ( {
93
- num : number ( ) . max ( 4 ) ,
117
+ let num = number ( ) ;
118
+ let shape = object ( { num } ) ;
94
119
95
- nested : object ( ) . shape ( {
96
- arr : array ( ) . of ( object ( ) . shape ( { num : num } ) ) ,
97
- } ) ,
98
- } ) ;
120
+ let inst = object ( {
121
+ num : number ( ) . max ( 4 ) ,
122
+
123
+ nested : object ( {
124
+ arr : array ( ) . of ( shape ) ,
125
+ } ) ,
126
+ } ) ;
99
127
100
128
reach ( inst , '' ) . should . equal ( inst ) ;
101
129
102
130
reach ( inst , 'nested.arr.num' ) . should . equal ( num ) ;
103
131
reach ( inst , 'nested.arr[].num' ) . should . equal ( num ) ;
104
132
reach ( inst , 'nested.arr[1].num' ) . should . equal ( num ) ;
133
+ reach ( inst , 'nested.arr[1]' ) . should . equal ( shape ) ;
134
+
105
135
reach ( inst , 'nested["arr"][1].num' ) . should . not . equal ( number ( ) ) ;
106
136
107
137
let valid = await reach ( inst , 'nested.arr[].num' ) . isValid ( 5 ) ;
@@ -185,7 +215,10 @@ describe('Yup', function() {
185
215
} )
186
216
. strict ( )
187
217
. validate ( {
188
- x : [ { type : 1 , foo : '4' } , { type : 2 , foo : '5' } ] ,
218
+ x : [
219
+ { type : 1 , foo : '4' } ,
220
+ { type : 2 , foo : '5' } ,
221
+ ] ,
189
222
} )
190
223
. should . be . rejected ( ) ;
191
224
err . message . should . match ( / m u s t b e a ` n u m b e r ` t y p e / ) ;
0 commit comments