@@ -13,9 +13,13 @@ const {
13
13
any,
14
14
anything,
15
15
arrayContaining,
16
+ arrayNotContaining,
16
17
objectContaining,
18
+ objectNotContaining,
17
19
stringContaining,
20
+ stringNotContaining,
18
21
stringMatching,
22
+ stringNotMatching,
19
23
} = require ( '../asymmetric_matchers' ) ;
20
24
21
25
test ( 'Any.asymmetricMatch()' , ( ) => {
@@ -89,6 +93,27 @@ test('ArrayContaining throws for non-arrays', () => {
89
93
} ) . toThrow ( ) ;
90
94
} ) ;
91
95
96
+ test ( 'ArrayNotContaining matches' , ( ) => {
97
+ jestExpect ( arrayNotContaining ( [ 'foo' ] ) . asymmetricMatch ( [ 'bar' ] ) ) . toBe ( true ) ;
98
+ } ) ;
99
+
100
+ test ( 'ArrayNotContaining does not match' , ( ) => {
101
+ [
102
+ arrayNotContaining ( [ ] ) . asymmetricMatch ( 'jest' ) ,
103
+ arrayNotContaining ( [ 'foo' ] ) . asymmetricMatch ( [ 'foo' ] ) ,
104
+ arrayNotContaining ( [ 'foo' ] ) . asymmetricMatch ( [ 'foo' , 'bar' ] ) ,
105
+ arrayNotContaining ( [ ] ) . asymmetricMatch ( { } ) ,
106
+ ] . forEach ( test => {
107
+ jestExpect ( test ) . toEqual ( false ) ;
108
+ } ) ;
109
+ } ) ;
110
+
111
+ test ( 'ArrayNotContaining throws for non-arrays' , ( ) => {
112
+ jestExpect ( ( ) => {
113
+ arrayNotContaining ( 'foo' ) . asymmetricMatch ( [ ] ) ;
114
+ } ) . toThrow ( ) ;
115
+ } ) ;
116
+
92
117
test ( 'ObjectContaining matches' , ( ) => {
93
118
[
94
119
objectContaining ( { } ) . asymmetricMatch ( 'jest' ) ,
@@ -139,32 +164,106 @@ test('ObjectContaining throws for non-objects', () => {
139
164
jestExpect ( ( ) => objectContaining ( 1337 ) . asymmetricMatch ( ) ) . toThrow ( ) ;
140
165
} ) ;
141
166
167
+ test ( 'ObjectNotContaining matches' , ( ) => {
168
+ [
169
+ objectNotContaining ( { } ) . asymmetricMatch ( 'jest' ) ,
170
+ objectNotContaining ( { foo : 'foo' } ) . asymmetricMatch ( { bar : 'bar' } ) ,
171
+ objectNotContaining ( { foo : 'foo' } ) . asymmetricMatch ( { foo : 'foox' } ) ,
172
+ objectNotContaining ( { foo : undefined } ) . asymmetricMatch ( { } ) ,
173
+ ] . forEach ( test => {
174
+ jestExpect ( test ) . toEqual ( true ) ;
175
+ } ) ;
176
+ } ) ;
177
+
178
+ test ( 'ObjectNotContaining does not match' , ( ) => {
179
+ [
180
+ objectNotContaining ( { foo : 'foo' } ) . asymmetricMatch ( {
181
+ foo : 'foo' ,
182
+ jest : 'jest' ,
183
+ } ) ,
184
+ objectNotContaining ( { foo : undefined } ) . asymmetricMatch ( { foo : undefined } ) ,
185
+ objectNotContaining ( {
186
+ first : objectNotContaining ( { second : { } } ) ,
187
+ } ) . asymmetricMatch ( { first : { second : { } } } ) ,
188
+ ] . forEach ( test => {
189
+ jestExpect ( test ) . toEqual ( false ) ;
190
+ } ) ;
191
+ } ) ;
192
+
193
+ test ( 'ObjectNotContaining throws for non-objects' , ( ) => {
194
+ jestExpect ( ( ) => objectNotContaining ( 1337 ) . asymmetricMatch ( ) ) . toThrow ( ) ;
195
+ } ) ;
196
+
142
197
test ( 'StringContaining matches string against string' , ( ) => {
143
198
jestExpect ( stringContaining ( 'en*' ) . asymmetricMatch ( 'queen*' ) ) . toBe ( true ) ;
144
199
jestExpect ( stringContaining ( 'en' ) . asymmetricMatch ( 'queue' ) ) . toBe ( false ) ;
145
- jestExpect ( stringContaining ( 'en' ) . asymmetricMatch ( { } ) ) . toBe ( false ) ;
146
200
} ) ;
147
201
148
202
test ( 'StringContaining throws for non-strings' , ( ) => {
149
203
jestExpect ( ( ) => {
150
204
stringContaining ( [ 1 ] ) . asymmetricMatch ( 'queen' ) ;
151
205
} ) . toThrow ( ) ;
206
+
207
+ jestExpect ( ( ) => {
208
+ stringContaining ( 'en*' ) . asymmetricMatch ( 1 ) ;
209
+ } ) . toThrow ( ) ;
210
+ } ) ;
211
+
212
+ test ( 'StringNotContaining matches string against string' , ( ) => {
213
+ jestExpect ( stringNotContaining ( 'en*' ) . asymmetricMatch ( 'queen*' ) ) . toBe ( false ) ;
214
+ jestExpect ( stringNotContaining ( 'en' ) . asymmetricMatch ( 'queue' ) ) . toBe ( true ) ;
215
+ } ) ;
216
+
217
+ test ( 'StringNotContaining throws for non-strings' , ( ) => {
218
+ jestExpect ( ( ) => {
219
+ stringNotContaining ( [ 1 ] ) . asymmetricMatch ( 'queen' ) ;
220
+ } ) . toThrow ( ) ;
221
+
222
+ jestExpect ( ( ) => {
223
+ stringNotContaining ( 'en*' ) . asymmetricMatch ( 1 ) ;
224
+ } ) . toThrow ( ) ;
152
225
} ) ;
153
226
154
227
test ( 'StringMatching matches string against regexp' , ( ) => {
155
228
jestExpect ( stringMatching ( / e n / ) . asymmetricMatch ( 'queen' ) ) . toBe ( true ) ;
156
229
jestExpect ( stringMatching ( / e n / ) . asymmetricMatch ( 'queue' ) ) . toBe ( false ) ;
157
- jestExpect ( stringMatching ( / e n / ) . asymmetricMatch ( { } ) ) . toBe ( false ) ;
158
230
} ) ;
159
231
160
232
test ( 'StringMatching matches string against string' , ( ) => {
161
233
jestExpect ( stringMatching ( 'en' ) . asymmetricMatch ( 'queen' ) ) . toBe ( true ) ;
162
234
jestExpect ( stringMatching ( 'en' ) . asymmetricMatch ( 'queue' ) ) . toBe ( false ) ;
163
- jestExpect ( stringMatching ( 'en' ) . asymmetricMatch ( { } ) ) . toBe ( false ) ;
164
235
} ) ;
165
236
166
237
test ( 'StringMatching throws for non-strings and non-regexps' , ( ) => {
167
238
jestExpect ( ( ) => {
168
239
stringMatching ( [ 1 ] ) . asymmetricMatch ( 'queen' ) ;
169
240
} ) . toThrow ( ) ;
170
241
} ) ;
242
+
243
+ test ( 'StringMatching throws for non-string actual values' , ( ) => {
244
+ jestExpect ( ( ) => {
245
+ stringMatching ( 'en' ) . asymmetricMatch ( 1 ) ;
246
+ } ) . toThrow ( ) ;
247
+ } ) ;
248
+
249
+ test ( 'StringNotMatching matches string against regexp' , ( ) => {
250
+ jestExpect ( stringNotMatching ( / e n / ) . asymmetricMatch ( 'queen' ) ) . toBe ( false ) ;
251
+ jestExpect ( stringNotMatching ( / e n / ) . asymmetricMatch ( 'queue' ) ) . toBe ( true ) ;
252
+ } ) ;
253
+
254
+ test ( 'StringNotMatching matches string against string' , ( ) => {
255
+ jestExpect ( stringNotMatching ( 'en' ) . asymmetricMatch ( 'queen' ) ) . toBe ( false ) ;
256
+ jestExpect ( stringNotMatching ( 'en' ) . asymmetricMatch ( 'queue' ) ) . toBe ( true ) ;
257
+ } ) ;
258
+
259
+ test ( 'StringNotMatching throws for non-strings and non-regexps' , ( ) => {
260
+ jestExpect ( ( ) => {
261
+ stringNotMatching ( [ 1 ] ) . asymmetricMatch ( 'queen' ) ;
262
+ } ) . toThrow ( ) ;
263
+ } ) ;
264
+
265
+ test ( 'StringNotMatching throws for non-string actual values' , ( ) => {
266
+ jestExpect ( ( ) => {
267
+ stringNotMatching ( 'en' ) . asymmetricMatch ( 1 ) ;
268
+ } ) . toThrow ( ) ;
269
+ } ) ;
0 commit comments