/
unexpected.spec.js
733 lines (632 loc) · 29.9 KB
/
unexpected.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
/*global describe, it, expect*/
// use this instead of Object.create in order to make the tests run in
// browsers that are not es5 compatible.
function create(o) {
function F() {}
F.prototype = o;
return new F();
}
describe('unexpected', function () {
describe('ok/truthy/falsy assertion', function () {
it('assert that the value is truthy or not', function () {
expect(1, 'to be ok');
expect(true, 'to be ok');
expect(true, 'not to be falsy');
expect({}, 'to be truthy');
expect(0, 'not to be ok');
expect(0, 'to be falsy');
expect(null, 'to be falsy');
expect(undefined, 'to be falsy');
});
it('throws when the assertion fails', function () {
expect(function () {
expect(0, 'to be ok');
}, 'to throw exception', 'expected 0 to be ok');
});
it('throws with message when the assertion fails', function () {
expect(function () {
expect(4 < 4, 'to be ok', '4 < 4');
}, "to throw exception", "expected false to be ok '4 < 4'");
});
it('throws with a stack trace that has the calling function as the top frame when the assertion fails (if the environment supports it)', function () {
if (Error.captureStackTrace || 'stack' in new Error()) {
expect(function TheCallingFunction() {
expect(4 < 4, 'to be ok');
}, 'to throw exception', function (err) {
expect(err.stack.split('\n')[1], 'to match', /TheCallingFunction/);
});
}
});
});
describe('be assertion', function () {
it('assert === equality', function () {
var obj = {};
expect(obj, 'to be', obj);
expect(obj, 'not to be', {});
expect(1, 'to be', 1);
expect(1, 'not to be', true);
expect('1', 'not to be', 1);
expect(null, 'not to be', undefined);
expect(null, 'to be null');
expect(0, 'not to be null');
expect(undefined, 'not to be null');
expect(undefined, 'to be undefined');
if (typeof Buffer !== 'undefined') {
var buffer = new Buffer([0x45, 0x59]);
expect(buffer, 'to be', buffer);
}
});
it('throws when the assertion fails', function () {
expect(function () {
expect('foo', 'to be', 'bar');
}, 'to throw exception', "expected 'foo' to be 'bar'");
expect(function () {
expect(true, 'not to be', true);
}, 'to throw exception', "expected true not to be true");
});
});
describe('a/an assertion', function () {
it('asserts typeof with support for array type and instanceof', function () {
expect(5, 'to be a', 'number');
expect(5, 'to be a number');
expect([], 'to be an', 'array');
expect([], 'to be an array');
expect([], 'to be an', 'object');
expect([], 'to be an object');
expect([], 'to be an', Array);
expect(/ab/, 'to be a', RegExp);
expect(/ab/, 'to be a regexp');
expect(123, 'not to be a regex');
expect(/ab/, 'to be a regex');
expect(/ab/, 'to be a regular expression');
expect(123, 'not to be a regular expression');
expect(null, 'not to be an', 'object');
expect(null, 'not to be an object');
expect(true, 'to be a', 'boolean');
expect(true, 'to be a boolean');
expect("".substring, 'to be a', 'function');
expect("".substring, 'to be a function');
});
it('throws when the assertion fails', function () {
expect(function () {
expect(5, 'to be a', Array);
}, 'to throw exception', /expected 5 to be a \[Function(: Array)?\]/);
expect(function () {
expect([], 'not to be an', 'array');
}, 'to throw exception', "expected [] not to be an 'array'");
});
});
describe('equal assertion', function () {
it('asserts loose equality that works with objects', function () {
expect({ a: 'b' }, 'to equal', { a: 'b' });
expect(1, 'to equal', '1');
expect(1, 'to equal', 1);
expect(null, 'not to equal', '1');
var now = new Date();
expect(now, 'to equal', now);
expect(now, 'to equal', new Date(now.getTime()));
expect({ now: now }, 'to equal', { now: now });
expect(null, 'to equal', null);
expect(null, 'not to equal', undefined);
expect(undefined, 'to equal', undefined);
expect(true, 'to equal', true);
expect(false, 'to equal', false);
expect({ a: { b: 'c' } }, 'to equal', { a: { b: 'c' } });
expect({ a: { b: 'c' } }, 'not to equal', { a: { b: 'd' } });
expect(/foo/, 'to equal', /foo/);
expect(/foo/i, 'not to equal', /foo/);
expect(/foo/gm, 'to equal', /foo/gm);
expect(/foo/m, 'not to equal', /foo/i);
expect(/foo/m, 'to equal', new RegExp('foo', 'm'));
if (typeof Buffer !== 'undefined') {
expect(new Buffer([0x45, 0x59]), 'to equal', new Buffer([0x45, 0x59]));
}
});
it('throws when the assertion fails', function () {
expect(function () {
expect({ a: { b: 'c'} }, 'to equal', { a: { b: 'd'} });
}, 'to throw exception', "expected { a: { b: 'c' } } to equal { a: { b: 'd' } }");
expect(function () {
expect({ a: 'b' }, 'not to equal', { a: 'b' });
}, 'to throw exception', "expected { a: 'b' } not to equal { a: 'b' }");
});
it("throws an error with 'expected' and 'actual' properties when not negated", function () {
var expected = 123,
actual = 456;
expect(function () {
expect(actual, 'to equal', expected);
}, 'to throw exception', function (e) {
expect(e.expected, 'to equal', expected);
expect(e.actual, 'to equal', actual);
});
});
it("throws an error without 'expected' and 'actual' properties when negated", function () {
expect(function () {
expect(123, 'not to equal', 123);
}, 'to throw exception', function (e) {
expect(e.expected, 'not to be ok');
expect(e.actual, 'not to be ok');
});
});
});
describe('exception assertion', function () {
it('fails if no exception is thrown', function () {
expect(function () {
expect(function () {
// Don't throw
}, 'to throw exception');
}, 'to throw', 'expected [Function] to throw exception');
});
it('fails if the argument is not a function', function () {
expect(function () {
expect(1, 'to throw exception');
}, 'to throw exception', "Assertion 'to throw exception' only supports functions");
});
it('given a function the function is called with the exception', function () {
expect(function () {
throw new SyntaxError();
}, 'to throw exception', function (e) {
expect(e, 'to be a', SyntaxError);
});
});
it('matches the message against the given regular expression', function () {
expect(function () {
throw new Error('matches the exception message');
}, 'to throw exception', /matches the exception message/);
expect(function () {
throw new Error('Other error');
}, 'not to throw exception', /matches the exception message/);
});
it('exactly matches the message against the given string', function () {
expect(function () {
throw new Error('matches the exception message');
}, 'to throw exception', 'matches the exception message');
expect(function () {
throw new Error('matches the exception message');
}, 'not to throw exception', 'the exception message');
});
});
describe('match assertion', function () {
it('tests that the subject matches the given regular expression', function () {
expect('test', 'to match', /.*st/);
expect('test', 'not to match', /foo/);
expect(null, 'not to match', /foo/);
});
it('throws when the assertion fails', function () {
expect(function () {
expect('test', 'to match', /foo/);
}, 'to throw exception', "expected 'test' to match /foo/");
});
});
describe('contain assertion', function () {
it('asserts indexOf for an array or string', function () {
expect([1, 2], 'to contain', 1);
expect([1, 2], 'to contain', 2, 1);
expect('hello world', 'to contain', 'world');
expect(null, 'not to contain', 'world');
});
it('throws when the assertion fails', function () {
expect(function () {
expect('hello world', 'to contain', 'foo');
}, 'to throw exception', "expected 'hello world' to contain 'foo'");
expect(function () {
expect('hello world', 'to contain', 'hello', 'foo');
}, 'to throw exception', "expected 'hello world' to contain 'hello', 'foo'");
expect(function () {
expect([1, 2], 'to contain', 2, 3);
}, 'to throw exception', "expected [ 1, 2 ] to contain 2, 3");
expect(function () {
expect(1, 'to contain', 1);
}, 'to throw exception', "Assertion 'to contain' only supports strings and arrays");
});
});
describe('length assertion', function () {
it('asserts array .length', function () {
expect([], 'to have length', 0);
expect([1,2,3], 'to have length', 3);
expect([1,2,3], 'not to have length', 4);
expect({ length: 4 }, 'to have length', 4);
});
it('throws when the assertion fails', function () {
expect(function () {
expect([1, 2], 'to have length', 3);
}, 'to throw exception', "expected [ 1, 2 ] to have length 3");
expect(function () {
expect(null, 'to have length', 4);
}, 'to throw exception', "Assertion 'to have length' only supports array like objects");
expect(function () {
expect({ length: 'foo' }, 'to have length', 4);
}, 'to throw exception', "Assertion 'to have length' only supports array like objects");
});
});
describe('property assertion', function () {
it('asserts presence of an own property (and value optionally)', function () {
expect([1, 2], 'to have property', 'length');
expect([1, 2], 'to have property', 'length', 2);
expect({a: 'b'}, 'to have property', 'a');
expect({a: 'b'}, 'to have property', 'a', 'b');
expect({a: 'b'}, 'to have property', 'toString');
expect({a: 'b'}, 'not to have property', 'b');
expect({a: 'b'}, 'to have own property', 'a');
expect(create({a: 'b'}), 'not to have own property', 'a');
expect(1, 'not to have property', 'a');
expect(null, 'not to have property', 'a');
expect(undefined, 'not to have property', 'a');
expect(true, 'not to have property', 'a');
expect(false, 'not to have property', 'a');
});
it('throws when the assertion fails', function () {
expect(function () {
expect({a: 'b'}, 'to have property', 'b');
}, 'to throw exception', "expected { a: 'b' } to have property 'b'");
expect(function () {
expect(null, 'to have property', 'b');
}, 'to throw exception', "expected null to have property 'b'");
expect(function () {
expect({a: 'b'}, 'to have property', 'a', 'c');
}, 'to throw exception', "expected { a: 'b' } to have property 'a', 'c'");
expect(function () {
// property expectations on value expects the property to be present
expect(null, 'not to have property', 'a', 'b');
}, 'to throw exception', "expected null not to have property 'a', 'b'");
expect(function () {
// property expectations on value expects the property to be present
expect(null, 'not to have own property', 'a', 'b');
}, 'to throw exception', "expected null not to have own property 'a', 'b'");
});
});
describe('empty assertion', function () {
it('asserts presence of an own property (and value optionally)', function () {
expect([], 'to be empty');
expect('', 'to be empty');
expect({}, 'to be empty');
expect({ length: 0, duck: 'typing' }, 'to be empty');
expect({ my: 'object' }, 'not to be empty');
expect([1,2,3], 'not to be empty');
});
it('throws when the assertion fails', function () {
expect(function () {
expect([1,2,3], 'to be empty');
}, 'to throw exception', "expected [ 1, 2, 3 ] to be empty");
expect(function () {
expect(null, 'to be empty');
}, 'to throw exception', "Assertion 'to be empty' only supports strings, arrays and objects");
});
});
describe('key assertion', function () {
it('asserts the presence of a key', function () {
expect({ a: 'b' }, 'to have key', 'a');
expect({ a: 'b' }, 'not to have key', 'b');
expect({ a: 'b', c: 'd' }, 'to not only have key', 'a');
expect({ a: 'b', c: 'd' }, 'to only have keys', 'a', 'c');
expect({ a: 'b', c: 'd' }, 'to only have keys', ['a', 'c']);
expect({ a: 'b', c: 'd', e: 'f' }, 'to not only have keys', ['a', 'c']);
expect(null, 'not to have key', 'a');
expect(undefined, 'not to have key', 'a');
expect(true, 'not to have key', 'a');
expect(false, 'not to have key', 'a');
});
it('throws when the assertion fails', function () {
expect(function () {
expect({ a: 'b', b: 'c' }, 'to have key', 'e');
}, 'to throw exception', "expected { a: 'b', b: 'c' } to have key 'e'");
expect(function () {
expect({ a: 'b', b: 'c' }, 'to only have key', 'b');
}, 'to throw exception', "expected { a: 'b', b: 'c' } to only have key 'b'");
expect(function () {
expect({ a: 'b', b: 'c' }, 'not to have key', 'b');
}, 'to throw exception', "expected { a: 'b', b: 'c' } not to have key 'b'");
expect(function () {
expect({ a: 'b', c: 'd' }, 'to not only have keys', ['a', 'c']);
}, 'to throw exception', "expected { a: 'b', c: 'd' } to not only have keys [ 'a', 'c' ]");
expect(function () {
expect({ a: 'b', c: 'd' }, 'to only have keys', 'a', 'd');
}, 'to throw exception', "expected { a: 'b', c: 'd' } to only have keys 'a', 'd'");
expect(function () {
expect({ a: 'b', c: 'd' }, 'to not only have keys', 'a', 'c');
}, 'to throw exception', "expected { a: 'b', c: 'd' } to not only have keys 'a', 'c'");
});
});
describe('finite assertion', function () {
it('asserts a finite number', function () {
expect(123, 'to be finite');
expect(0, 'to be finite');
expect(Infinity, 'not to be finite');
expect(-Infinity, 'not to be finite');
expect(NaN, 'not to be finite');
expect(null, 'not to be finite');
expect({}, 'not to be finite');
it('throws when the assertion fails', function () {
expect(function () {
expect(Infinity, 'to be finite');
}, 'to throw exception', 'expected Infinity to be finite');
});
});
});
describe('finite assertion', function () {
it('asserts a infinite number', function () {
expect(123, 'not to be infinite');
expect(0, 'not to be infinite');
expect(Infinity, 'to be infinite');
expect(-Infinity, 'to be infinite');
expect(NaN, 'not to be infinite');
expect(null, 'not to be infinite');
expect({}, 'not to be infinite');
it('throws when the assertion fails', function () {
expect(function () {
expect(123, 'to be finite');
}, 'to throw exception', 'expected 123 to be infinite');
});
});
});
describe('within assertion', function () {
it('asserts a number within a range', function () {
expect(0, 'to be within', 0, 4);
expect(1, 'to be within', 0, 4);
expect(4, 'to be within', 0, 4);
expect(-1, 'not to be within', 0, 4);
expect(5, 'not to be within', 0, 4);
});
it('throws when the assertion fails', function () {
expect(function () {
expect(4, 'not to be within', 0, 4);
}, 'to throw exception', "expected 4 not to be within '0..4'");
expect(function () {
expect(null, 'not to be within', 0, 4);
}, 'to throw exception', "expected null not to be within '0..4'");
});
});
describe('less than assertion', function () {
it('asserts <', function () {
expect(0, 'to be less than', 4);
expect(0, 'to be below', 1);
expect(3, 'to be <', 4);
expect(3, '<', 4);
});
it('throws when the assertion fails', function () {
expect(function () {
expect(0, 'to be less than', 0);
}, 'to throw exception', "expected 0 to be less than 0");
});
});
describe('less than or equal assertion', function () {
it('asserts <=', function () {
expect(0, 'to be less than or equal to', 4);
expect(4, 'to be <=', 4);
expect(3, '<=', 4);
});
it('throws when the assertion fails', function () {
expect(function () {
expect(0, 'to be less than or equal to', -1);
}, 'to throw exception', "expected 0 to be less than or equal to -1");
});
});
describe('greater than assertion', function () {
it('assert >', function () {
expect(3, 'to be greater than', 2);
expect(1, 'to be above', 0);
expect(4, 'to be >', 3);
expect(4, '>', 3);
});
it('throws when the assertion fails', function () {
expect(function () {
expect(0, 'to be greater than', 0);
}, 'to throw exception', "expected 0 to be greater than 0");
});
});
describe('greater than or equal assertion', function () {
it('assert >=', function () {
expect(3, 'to be greater than or equal to', 2);
expect(3, 'to be >=', 3);
expect(3, '>=', 3);
});
it('throws when the assertion fails', function () {
expect(function () {
expect(-1, 'to be greater than or equal to', 0);
}, 'to throw exception', "expected -1 to be greater than or equal to 0");
});
});
describe('positive assertion', function () {
it('assert that a number is positive', function () {
expect(3, 'to be positive');
});
it('throws when the assertion fails', function () {
expect(function () {
expect(0, 'to be positive');
}, 'to throw exception', "expected 0 to be positive");
});
});
describe('negative assertion', function () {
it('assert that a number is negative', function () {
expect(-1, 'to be negative');
});
it('throws when the assertion fails', function () {
expect(function () {
expect(0, 'to be negative');
}, 'to throw exception', "expected 0 to be negative");
});
});
describe('to be NaN assertion', function () {
it('assert that the value is NaN or not', function () {
expect(NaN, 'to be NaN');
expect({}, 'to be NaN');
expect(2, 'not to be NaN');
expect(null, 'not to be NaN');
expect(undefined, 'to be NaN');
expect("String", 'to be NaN');
});
it('fails when the assertion fails', function () {
expect(function () {
expect(0, 'to be NaN');
}, 'to throw', "expected 0 to be NaN");
expect(function () {
expect(NaN, 'not to be NaN');
}, 'to throw', "expected NaN not to be NaN");
});
});
describe('fail assertion', function () {
it('throws an error', function () {
expect(function () {
expect.fail();
}, 'to throw exception', "explicit failure");
});
it('throws an error with a given message', function () {
expect(function () {
expect.fail('fail with error message');
}, 'to throw exception', "fail with error message");
});
it('supports placeholders', function () {
expect(function () {
expect.fail('{0} was expected to be {1}', 0, 'zero');
}, 'to throw exception', "0 was expected to be 'zero'");
expect(function () {
expect.fail('{0} was expected to be {1}', 0);
}, 'to throw exception', "0 was expected to be {1}");
});
it('throws if the assertion does not exists', function () {
expect(function () {
expect(1, "foo bar", 2);
}, 'to throw exception', 'Unknown assertion "foo bar", did you mean: "to be"');
});
});
function sortBy(arr, property) {
arr.sort(function (x, y) {
var xp = x[property];
var yp = y[property];
if (xp > yp) { return 1; }
if (xp < yp) { return -1; }
return 0;
});
}
describe('addAssertion', function () {
describe('pattern', function () {
it("must be a string", function () {
expect(function () {
expect.addAssertion(null, function () {});
}, 'to throw', "Assertion patterns must be a non empty string");
});
it("must be a non empty", function () {
expect(function () {
expect.addAssertion('', function () {});
}, 'to throw', "Assertion patterns must be a non empty string");
});
it("can't start or end with whitespace", function () {
expect(function () {
expect.addAssertion(' ', function () {});
}, 'to throw', "Assertion patterns can't start or end with whitespace");
});
it("can't start with whitespace", function () {
expect(function () {
expect.addAssertion(' foo', function () {});
}, 'to throw', "Assertion patterns can't start or end with whitespace");
});
it("can't end with whitespace", function () {
expect(function () {
expect.addAssertion('foo ', function () {});
}, 'to throw', "Assertion patterns can't start or end with whitespace");
});
it("must not contain unbalanced brackets", function () {
expect(function () {
expect.addAssertion('foo [', function () {});
}, 'to throw', "Assertion patterns must not contain unbalanced brackets: 'foo ['");
expect(function () {
expect.addAssertion('foo ]', function () {});
}, 'to throw', "Assertion patterns must not contain unbalanced brackets: 'foo ]'");
});
it("must not contain unbalanced parenthesis", function () {
expect(function () {
expect.addAssertion('foo (', function () {});
}, 'to throw', "Assertion patterns must not contain unbalanced parenthesis: 'foo ('");
expect(function () {
expect.addAssertion('foo )', function () {});
}, 'to throw', "Assertion patterns must not contain unbalanced parenthesis: 'foo )'");
});
it("must not only contain flags", function () {
expect(function () {
expect.addAssertion('[foo] [bar]', function () {});
}, 'to throw', "Assertion patterns must not only contain flags");
});
describe('flags', function () {
it("must not be empty", function () {
expect(function () {
expect.addAssertion('foo []', function () {});
}, 'to throw', "Assertion patterns must not contain empty flags: 'foo []'");
});
it("must not contain brackets", function () {
expect(function () {
expect.addAssertion('foo [[bar]', function () {});
}, 'to throw', "Assertion patterns must not contain flags with brackets: 'foo [[bar]'");
expect(function () {
expect.addAssertion('foo [[bar]]', function () {});
}, 'to throw', "Assertion patterns must not contain flags with brackets: 'foo [[bar]]'");
});
it("must not contain parenthesis", function () {
expect(function () {
expect.addAssertion('foo [(bar]', function () {});
}, 'to throw', "Assertion patterns must not contain flags with parenthesis: 'foo [(bar]'");
expect(function () {
expect.addAssertion('foo [bar)]', function () {});
}, 'to throw', "Assertion patterns must not contain flags with parenthesis: 'foo [bar)]'");
});
});
describe('alternations', function () {
it("must not be empty", function () {
expect(function () {
expect.addAssertion('foo ()', function () {});
}, 'to throw', "Assertion patterns must not contain empty alternations: 'foo ()'");
expect(function () {
expect.addAssertion('foo (bar|)', function () {});
}, 'to throw', "Assertion patterns must not contain empty alternations: 'foo (bar|)'");
expect(function () {
expect.addAssertion('foo (||)', function () {});
}, 'to throw', "Assertion patterns must not contain empty alternations: 'foo (||)'");
expect(function () {
expect.addAssertion('foo (|bar|)', function () {});
}, 'to throw', "Assertion patterns must not contain empty alternations: 'foo (|bar|)'");
});
it("must not contain brackets", function () {
expect(function () {
expect.addAssertion('foo ([bar)', function () {});
}, 'to throw', "Assertion patterns must not contain alternations with brackets: 'foo ([bar)'");
expect(function () {
expect.addAssertion('foo (bar])', function () {});
}, 'to throw', "Assertion patterns must not contain alternations with brackets: 'foo (bar])'");
});
it("must not contain parenthesis", function () {
expect(function () {
expect.addAssertion('foo ((bar)', function () {});
}, 'to throw', "Assertion patterns must not contain alternations with parenthesis: 'foo ((bar)'");
expect(function () {
expect.addAssertion('foo ((bar))', function () {});
}, 'to throw', "Assertion patterns must not contain alternations with parenthesis: 'foo ((bar))'");
});
});
});
});
describe('internal', function () {
describe('expandPattern', function () {
it('expands patterns containing multiple flags', function () {
var expanded = expect.internal.expandPattern('foo [not] [only] bar');
sortBy(expanded, 'text');
expect(expanded, 'to equal', [
{ text: 'foo bar', flags: []},
{ text: 'foo not bar', flags: ['not']},
{ text: 'foo not only bar', flags: ['not', 'only']},
{ text: 'foo only bar', flags: ['only']}
]);
expect(expanded.length, 'to be', 4);
});
it('expands patterns alternations', function () {
var expanded = expect.internal.expandPattern('foo (bar|bar baz) (qux|quux)');
sortBy(expanded, 'text');
expect(expanded, 'to equal', [
{ text: 'foo bar baz quux', flags: []},
{ text: 'foo bar baz qux', flags: []},
{ text: 'foo bar quux', flags: []},
{ text: 'foo bar qux', flags: []}
]);
expect(expanded.length, 'to be', 4);
});
});
});
});