@@ -55,13 +55,7 @@ function assertComponentImpl(path, result, expectedElement) {
55
55
. forEach ( ( attr ) => {
56
56
const resultValue = result . props [ attr ] ;
57
57
const expectedValue = expectedElement . props [ attr ] ;
58
- if ( typeof expectedValue === "object" && ! Array . isArray ( expectedValue ) ) {
59
- assertObject ( `${ pathName } .${ attr } ` , resultValue , expectedValue ) ;
60
- } else if ( typeof expectedValue === "function" ) {
61
- // functions could differ !!!
62
- } else {
63
- assertAttrValue ( `${ pathName } .${ attr } ` , resultValue , expectedValue ) ;
64
- }
58
+ assertAny ( `${ pathName } .${ attr } ` , resultValue , expectedValue ) ;
65
59
} ) ;
66
60
67
61
const children = getComponentChildren ( result ) ;
@@ -97,30 +91,59 @@ function assertComponentImpl(path, result, expectedElement) {
97
91
}
98
92
99
93
/**
100
- *
94
+ * @param {string } name
95
+ * @param {any } resultValue
96
+ * @param {any } expectedValue
97
+ */
98
+ function assertAny ( name , resultValue , expectedValue ) {
99
+ if ( typeof expectedValue === "object" ) {
100
+ if ( Array . isArray ( expectedValue ) ) {
101
+ assertArray ( name , resultValue , expectedValue ) ;
102
+ } else {
103
+ assertObject ( name , resultValue , expectedValue ) ;
104
+ }
105
+ } else if ( typeof expectedValue === "function" ) {
106
+ // functions could differ !!!
107
+ } else {
108
+ assertAttrValue ( name , resultValue , expectedValue ) ;
109
+ }
110
+ }
111
+
112
+ /**
113
+ * @param {string } name
114
+ * @param {any } resultArray
115
+ * @param {any[] } expectedArray
116
+ */
117
+ function assertArray ( name , resultArray , expectedArray ) {
118
+ assertAttrValue ( `${ name } .isArray` , Array . isArray ( resultArray ) , true ) ;
119
+ assertAttrValue ( `${ name } .length` , resultArray . length , expectedArray . length ) ;
120
+
121
+ if ( resultArray !== expectedArray ) {
122
+ expectedArray . forEach ( ( expectedValue , index ) => {
123
+ const resultValue = resultArray [ index ] ;
124
+ assertAny ( `${ name } .${ index } ` , resultValue , expectedValue ) ;
125
+ } ) ;
126
+ }
127
+ }
128
+
129
+ /**
101
130
* @param {string } name
102
131
* @param {any } resultValue
103
132
* @param {any } expectedObject
104
133
*/
105
134
function assertObject ( name , resultValue , expectedObject ) {
106
- assertAttrValue ( name , typeof resultValue , "object" ) ;
135
+ assertAttrValue ( ` ${ name } .typeof` , typeof resultValue , "object" ) ;
107
136
108
137
if ( resultValue !== expectedObject ) {
109
138
const resultObject = resultValue ;
110
139
const resultKeys = new Set ( Object . keys ( resultObject ) ) ;
111
140
const expectedKeys = new Set ( Object . keys ( expectedObject ) ) ;
112
- assertAttrValue ( name , resultKeys , expectedKeys ) ;
141
+ assertAttrValue ( ` ${ name } .keys` , resultKeys , expectedKeys ) ;
113
142
114
143
expectedKeys . forEach ( ( key ) => {
115
144
const resultValue = resultObject [ key ] ;
116
145
const expectedValue = expectedObject [ key ] ;
117
- if ( typeof expectedValue === "object" && ! Array . isArray ( expectedValue ) ) {
118
- assertObject ( `${ name } .${ key } ` , resultValue , expectedValue ) ;
119
- } else if ( typeof expectedValue === "function" ) {
120
- // functions could differ !!!
121
- } else {
122
- assertAttrValue ( `${ name } .${ key } ` , resultValue , expectedValue ) ;
123
- }
146
+ assertAny ( `${ name } .${ key } ` , resultValue , expectedValue ) ;
124
147
} ) ;
125
148
}
126
149
}
0 commit comments