forked from winsonwq/karma-e2e-dsl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
should.js
2341 lines (2008 loc) · 62.8 KB
/
should.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
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(e){if("function"==typeof bootstrap)bootstrap("should",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeShould=e}else"undefined"!=typeof window?window.should=e():global.should=e()})(function(){var define,ses,bootstrap,module,exports;
return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// Taken from node's assert module, because it sucks
// and exposes next to nothing useful.
var util = require('./util');
module.exports = _deepEqual;
var pSlice = Array.prototype.slice;
function _deepEqual(actual, expected) {
// 7.1. All identical values are equivalent, as determined by ===.
if (actual === expected) {
return true;
} else if (util.isBuffer(actual) && util.isBuffer(expected)) {
if (actual.length != expected.length) return false;
for (var i = 0; i < actual.length; i++) {
if (actual[i] !== expected[i]) return false;
}
return true;
// 7.2. If the expected value is a Date object, the actual value is
// equivalent if it is also a Date object that refers to the same time.
} else if (util.isDate(actual) && util.isDate(expected)) {
return actual.getTime() === expected.getTime();
// 7.3 If the expected value is a RegExp object, the actual value is
// equivalent if it is also a RegExp object with the same source and
// properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
} else if (util.isRegExp(actual) && util.isRegExp(expected)) {
return actual.source === expected.source &&
actual.global === expected.global &&
actual.multiline === expected.multiline &&
actual.lastIndex === expected.lastIndex &&
actual.ignoreCase === expected.ignoreCase;
// 7.4. Other pairs that do not both pass typeof value == 'object',
// equivalence is determined by ==.
} else if (!util.isObject(actual) && !util.isObject(expected)) {
return actual == expected;
// 7.5 For all other Object pairs, including Array objects, equivalence is
// determined by having the same number of owned properties (as verified
// with Object.prototype.hasOwnProperty.call), the same set of keys
// (although not necessarily the same order), equivalent values for every
// corresponding key, and an identical 'prototype' property. Note: this
// accounts for both named and indexed properties on Arrays.
} else {
return objEquiv(actual, expected);
}
}
function objEquiv (a, b) {
if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
return false;
// an identical 'prototype' property.
if (a.prototype !== b.prototype) return false;
//~~~I've managed to break Object.keys through screwy arguments passing.
// Converting to array solves the problem.
if (util.isArguments(a)) {
if (!util.isArguments(b)) {
return false;
}
a = pSlice.call(a);
b = pSlice.call(b);
return _deepEqual(a, b);
}
try{
var ka = Object.keys(a),
kb = Object.keys(b),
key, i;
} catch (e) {//happens when one is a string literal and the other isn't
return false;
}
// having the same number of owned properties (keys incorporates
// hasOwnProperty)
if (ka.length != kb.length)
return false;
//the same set of keys (although not necessarily the same order),
ka.sort();
kb.sort();
//~~~cheap key test
for (i = ka.length - 1; i >= 0; i--) {
if (ka[i] != kb[i])
return false;
}
//equivalent values for every corresponding key, and
//~~~possibly expensive deep test
for (i = ka.length - 1; i >= 0; i--) {
key = ka[i];
if (!_deepEqual(a[key], b[key])) return false;
}
return true;
}
},{"./util":4}],2:[function(require,module,exports){
//copy of node http module status codes
//https://github.com/joyent/node/blob/master/lib/_http_server.js
var STATUS_CODES = exports.STATUS_CODES = {
100 : 'Continue',
101 : 'Switching Protocols',
102 : 'Processing', // RFC 2518, obsoleted by RFC 4918
200 : 'OK',
201 : 'Created',
202 : 'Accepted',
203 : 'Non-Authoritative Information',
204 : 'No Content',
205 : 'Reset Content',
206 : 'Partial Content',
207 : 'Multi-Status', // RFC 4918
300 : 'Multiple Choices',
301 : 'Moved Permanently',
302 : 'Moved Temporarily',
303 : 'See Other',
304 : 'Not Modified',
305 : 'Use Proxy',
307 : 'Temporary Redirect',
400 : 'Bad Request',
401 : 'Unauthorized',
402 : 'Payment Required',
403 : 'Forbidden',
404 : 'Not Found',
405 : 'Method Not Allowed',
406 : 'Not Acceptable',
407 : 'Proxy Authentication Required',
408 : 'Request Time-out',
409 : 'Conflict',
410 : 'Gone',
411 : 'Length Required',
412 : 'Precondition Failed',
413 : 'Request Entity Too Large',
414 : 'Request-URI Too Large',
415 : 'Unsupported Media Type',
416 : 'Requested Range Not Satisfiable',
417 : 'Expectation Failed',
418 : 'I\'m a teapot', // RFC 2324
422 : 'Unprocessable Entity', // RFC 4918
423 : 'Locked', // RFC 4918
424 : 'Failed Dependency', // RFC 4918
425 : 'Unordered Collection', // RFC 4918
426 : 'Upgrade Required', // RFC 2817
428 : 'Precondition Required', // RFC 6585
429 : 'Too Many Requests', // RFC 6585
431 : 'Request Header Fields Too Large',// RFC 6585
500 : 'Internal Server Error',
501 : 'Not Implemented',
502 : 'Bad Gateway',
503 : 'Service Unavailable',
504 : 'Gateway Time-out',
505 : 'HTTP Version Not Supported',
506 : 'Variant Also Negotiates', // RFC 2295
507 : 'Insufficient Storage', // RFC 4918
509 : 'Bandwidth Limit Exceeded',
510 : 'Not Extended', // RFC 2774
511 : 'Network Authentication Required' // RFC 6585
};
module.exports.STATUS_CODES = STATUS_CODES;
},{}],3:[function(require,module,exports){
/*!
* Should
* Copyright(c) 2010-2012 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
/**
* Module dependencies.
*/
var util = require('./util')
, assert = require('assert')
, AssertionError = assert.AssertionError
, statusCodes = require('./http').STATUS_CODES
, eql = require('./eql')
, inspect = require('util').inspect;
/**
* Our function should
* @param obj
* @returns {Assertion}
*/
var should = function(obj) {
return new Assertion(util.isWrapperType(obj) ? obj.valueOf(): obj);
};
should.inspect = inspect;
/**
* Expose assert to should
*
* This allows you to do things like below
* without require()ing the assert module.
*
* should.equal(foo.bar, undefined);
*
*/
util.merge(should, assert);
/**
* Assert _obj_ exists, with optional message.
*
* @param {*} obj
* @param {String} [msg]
* @api public
*/
should.exist = should.exists = function(obj, msg) {
if(null == obj) {
throw new AssertionError({
message: msg || ('expected ' + should.inspect(obj) + ' to exist')
, stackStartFunction: should.exist
});
}
};
/**
* Asserts _obj_ does not exist, with optional message.
*
* @param {*} obj
* @param {String} [msg]
* @api public
*/
should.not = {};
should.not.exist = should.not.exists = function(obj, msg){
if (null != obj) {
throw new AssertionError({
message: msg || ('expected ' + should.inspect(obj) + ' to not exist')
, stackStartFunction: should.not.exist
});
}
};
/**
* Expose should to external world.
*/
exports = module.exports = should;
/**
* Expose api via `Object#should`.
*
* @api public
*/
Object.defineProperty(Object.prototype, 'should', {
set: function(){},
get: function(){
return should(this);
},
configurable: true
});
/**
* Initialize a new `Assertion` with the given _obj_.
*
* @param {*} obj
* @api private
*/
var Assertion = should.Assertion = function Assertion(obj) {
this.obj = obj;
};
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Prototype.
*/
Assertion.prototype = {
/**
* Assert _expr_ with the given _msg_ and _negatedMsg_.
*
* @param {Boolean} expr
* @param {function} msg
* @param {function} negatedMsg
* @param {Object} [expected]
* @param {Boolean} [showDiff]
* @param {String} [description]
* @api private
*/
assert: function(expr, msg, negatedMsg, expected, showDiff, description){
msg = this.negate ? negatedMsg : msg
var ok = this.negate ? !expr : expr
, obj = this.obj;
if (ok) return;
var err = new AssertionError({
message: msg.call(this)
, actual: obj
, expected: expected
, stackStartFunction: this.assert
, negated: this.negate
});
err.showDiff = showDiff;
err.description = description
throw err;
},
/**
* Dummy getter.
*
* @api public
*/
get an() {
return this;
},
/**
* Dummy getter.
*
* @api public
*/
get of() {
return this;
},
/**
* Dummy getter.
*
* @api public
*/
get a() {
return this;
},
/**
* Dummy getter.
*
* @api public
*/
get and() {
return this;
},
/**
* Dummy getter.
*
* @api public
*/
get be() {
return this;
},
/**
* Dummy getter.
*
* @api public
*/
get have() {
return this;
},
/**
* Dummy getter.
*
* @api public
*/
get with() {
return this;
},
/**
* Negation modifier.
*
* @api public
*/
get not() {
this.negate = true;
return this;
},
/**
* Get object inspection string.
*
* @return {String}
* @api private
*/
get inspect() {
return should.inspect(this.obj);
},
/**
* Assert instanceof `Arguments`.
*
* @api public
*/
get arguments() {
this.assert(
util.isArguments(this.obj)
, function(){ return 'expected ' + this.inspect + ' to be arguments' }
, function(){ return 'expected ' + this.inspect + ' to not be arguments' });
return this;
},
/**
* Assert that object is empty.
*
* @api public
*/
get empty() {
var length = this.obj.length;
if(util.isString(this.obj) || Array.isArray(this.obj) || util.isArguments(this.obj)) {
this.assert(
0 === length
, function(){ return 'expected ' + this.inspect + ' to be empty' }
, function(){ return 'expected ' + this.inspect + ' not to be empty' });
} else {
var ok = true;
for (var prop in this.obj) {
if(hasOwnProperty.call(this.obj, prop)) {
ok = false;
break;
}
}
this.assert(
ok
, function(){ return 'expected ' + this.inspect + ' to be empty' }
, function(){ return 'expected ' + this.inspect + ' not to be empty' });
}
return this;
},
/**
* Assert ok.
*
* @api public
*/
get ok() {
this.assert(
this.obj
, function(){ return 'expected ' + this.inspect + ' to be truthy' }
, function(){ return 'expected ' + this.inspect + ' to be falsey' });
return this;
},
/**
* Assert true.
*
* @api public
*/
get true() {
this.assert(
true === this.obj
, function(){ return 'expected ' + this.inspect + ' to be true' }
, function(){ return 'expected ' + this.inspect + ' not to be true' });
return this;
},
/**
* Assert false.
*
* @api public
*/
get false() {
this.assert(
false === this.obj
, function(){ return 'expected ' + this.inspect + ' to be false' }
, function(){ return 'expected ' + this.inspect + ' not to be false' });
return this;
},
/**
* Assert NaN.
*
* @api public
*/
get NaN() {
this.assert(
util.isNumber(this.obj) && isNaN(this.obj)
, function(){ return 'expected ' + this.inspect + ' to be NaN' }
, function(){ return 'expected ' + this.inspect + ' not to be NaN' });
return this;
},
/**
* Assert Infinity.
*
* @api public
*/
get Infinity() {
this.assert(
util.isNumber(this.obj) && !isNaN(this.obj) && !isFinite(this.obj)
, function(){ return 'expected ' + this.inspect + ' to be Infinity' }
, function(){ return 'expected ' + this.inspect + ' not to be Infinity' });
return this;
},
/**
* Assert equal.
*
* @param {*} val
* @param {String} description
* @api public
*/
eql: function(val, description){
this.assert(
eql(val, this.obj)
, function(){ return 'expected ' + this.inspect + ' to equal ' + should.inspect(val) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not equal ' + should.inspect(val) + (description ? " | " + description : "") }
, val
, true
, description);
return this;
},
/**
* Assert strict equal.
*
* @param {*} val
* @param {String} description
* @api public
*/
equal: function(val, description){
this.assert(
val === this.obj
, function(){ return 'expected ' + this.inspect + ' to equal ' + should.inspect(val) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not equal ' + should.inspect(val) + (description ? " | " + description : "") }
, val
, void 0
, description);
return this;
},
/**
* Assert within start to finish (inclusive).
*
* @param {Number} start
* @param {Number} finish
* @param {String} description
* @api public
*/
within: function(start, finish, description){
var range = start + '..' + finish;
this.assert(
this.obj >= start && this.obj <= finish
, function(){ return 'expected ' + this.inspect + ' to be within ' + range + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not be within ' + range + (description ? " | " + description : "") }
, void 0
, void 0
, description);
return this;
},
/**
* Assert within value +- delta (inclusive).
*
* @param {Number} value
* @param {Number} delta
* @param {String} description
* @api public
*/
approximately: function(value, delta, description) {
this.assert(
Math.abs(this.obj - value) <= delta
, function(){ return 'expected ' + this.inspect + ' to be approximately ' + value + " +- " + delta + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not be approximately ' + value + " +- " + delta + (description ? " | " + description : "") }
, void 0
, void 0
, description);
return this;
},
/**
* Assert typeof.
*
* @param {*} type
* @param {String} description
* @api public
*/
type: function(type, description){
this.assert(
type == typeof this.obj
, function(){ return 'expected ' + this.inspect + ' to have type ' + type + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' not to have type ' + type + (description ? " | " + description : "") }
, void 0
, void 0
, description);
return this;
},
/**
* Assert instanceof.
*
* @param {Function} constructor
* @param {String} description
* @api public
*/
instanceof: function(constructor, description){
var name = constructor.name;
this.assert(
this.obj instanceof constructor
, function(){ return 'expected ' + this.inspect + ' to be an instance of ' + name + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' not to be an instance of ' + name + (description ? " | " + description : "") }
, void 0
, void 0
, description);
return this;
},
/**
* Assert if given object is a function.
*/
get Function(){
this.assert(
util.isFunction(this.obj)
, function(){ return 'expected ' + this.inspect + ' to be a function' }
, function(){ return 'expected ' + this.inspect + ' not to be a function' });
return this;
},
/**
* Assert given object is an object.
*/
get Object(){
this.assert(
util.isObject(this.obj) && !Array.isArray(this.obj)
, function(){ return 'expected ' + this.inspect + ' to be an object' }
, function(){ return 'expected ' + this.inspect + ' not to be an object' });
return this;
},
/**
* Assert given object is a string
*/
get String(){
this.assert(
util.isString(this.obj)
, function(){ return 'expected ' + this.inspect + ' to be a string' }
, function(){ return 'expected ' + this.inspect + ' not to be a string' });
return this;
},
/**
* Assert given object is an array
*/
get Array(){
this.assert(
Array.isArray(this.obj)
, function(){ return 'expected ' + this.inspect + ' to be an array' }
, function(){ return 'expected ' + this.inspect + ' not to be an array' });
return this;
},
/**
* Assert given object is a number. NaN and Infinity are not numbers.
*/
get Number(){
this.assert(
util.isNumber(this.obj) && isFinite(this.obj) && !isNaN(this.obj)
, function(){ return 'expected ' + this.inspect + ' to be a number' }
, function(){ return 'expected ' + this.inspect + ' not to be a number' });
return this;
},
/**
* Assert given object is a boolean
*/
get Boolean(){
this.assert(
util.isBoolean(this.obj)
, function(){ return 'expected ' + this.inspect + ' to be a boolean' }
, function(){ return 'expected ' + this.inspect + ' not to be a boolean' });
return this;
},
/**
* Assert given object is an error
*/
get Error() {
this.assert(
util.isError(this.obj)
, function(){ return 'expected ' + this.inspect + ' to be an error' }
, function(){ return 'expected ' + this.inspect + ' not to be an error' });
return this;
},
/**
* Assert numeric value above _n_.
*
* @param {Number} n
* @param {String} description
* @api public
*/
above: function(n, description){
this.assert(
this.obj > n
, function(){ return 'expected ' + this.inspect + ' to be above ' + n + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to be below ' + n + (description ? " | " + description : "") }
, void 0
, void 0
, description);
return this;
},
/**
* Assert numeric value below _n_.
*
* @param {Number} n
* @param {String} description
* @api public
*/
below: function(n, description){
this.assert(
this.obj < n
, function(){ return 'expected ' + this.inspect + ' to be below ' + n + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to be above ' + n + (description ? " | " + description : "") }
, void 0
, void 0
, description);
return this;
},
/**
* Assert string value matches _regexp_.
*
* @param {RegExp} regexp
* @param {String} description
* @api public
*/
match: function(regexp, description){
this.assert(
regexp.exec(this.obj)
, function(){ return 'expected ' + this.inspect + ' to match ' + regexp + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' not to match ' + regexp + (description ? " | " + description : "") }
, void 0
, void 0
, description);
return this;
},
/**
* Assert property "length" exists and has value of _n_.
*
* @param {Number} n
* @param {String} description
* @api public
*/
length: function(n, description){
this.obj.should.have.property('length');
var len = this.obj.length;
this.assert(
n == len
, function(){ return 'expected ' + this.inspect + ' to have a length of ' + n + ' but got ' + len + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not have a length of ' + len + (description ? " | " + description : "") }
, void 0
, void 0
, description);
return this;
},
/**
* Assert property _name_ exists, with optional _val_.
*
* @param {String} name
* @param {*} [val]
* @param {String} description
* @api public
*/
property: function(name, val, description){
if (this.negate && undefined !== val) {
if (undefined === this.obj[name]) {
throw new Error(this.inspect + ' has no property ' + should.inspect(name) + (description ? " | " + description : ""));
}
} else {
this.assert(
undefined !== this.obj[name]
, function(){ return 'expected ' + this.inspect + ' to have a property ' + should.inspect(name) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not have a property ' + should.inspect(name) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
}
if (undefined !== val) {
this.assert(
val === this.obj[name]
, function(){ return 'expected ' + this.inspect + ' to have a property ' + should.inspect(name)
+ ' of ' + should.inspect(val) + ', but got ' + should.inspect(this.obj[name]) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not have a property ' + should.inspect(name) + ' of ' + should.inspect(val) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
}
this.obj = this.obj[name];
return this;
},
/**
* Asset have given properties
* @param {Array|String ...} names
* @api public
*/
properties: function(names) {
var str
, ok = true;
names = names instanceof Array
? names
: Array.prototype.slice.call(arguments);
var len = names.length;
if (!len) throw new Error('names required');
// make sure they're all present
ok = names.every(function(name){
return this.obj[name] !== undefined;
}, this);
// key string
if (len > 1) {
names = names.map(function(name){
return should.inspect(name);
});
var last = names.pop();
str = names.join(', ') + ', and ' + last;
} else {
str = should.inspect(names[0]);
}
// message
str = 'have ' + (len > 1 ? 'properties ' : 'a property ') + str;
this.assert(
ok
, function(){ return 'expected ' + this.inspect + ' to ' + str }
, function(){ return 'expected ' + this.inspect + ' to not ' + str });
return this;
},
/**
* Assert own property _name_ exists.
*
* @param {String} name
* @param {String} description
* @api public
*/
ownProperty: function(name, description){
this.assert(
hasOwnProperty.call(this.obj, name)
, function(){ return 'expected ' + this.inspect + ' to have own property ' + should.inspect(name) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not have own property ' + should.inspect(name) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
this.obj = this.obj[name];
return this;
},
/**
* Assert that string starts with `str`.
* @param {String} str
* @param {String} description
* @api public
*/
startWith: function(str, description) {
this.assert(0 === this.obj.indexOf(str)
, function() { return 'expected ' + this.inspect + ' to start with ' + should.inspect(str) + (description ? " | " + description : "") }
, function() { return 'expected ' + this.inspect + ' to not start with ' + should.inspect(str) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
return this;
},
/**
* Assert that string ends with `str`.
* @param {String} str
* @param {String} description
* @api public
*/
endWith: function(str, description) {
this.assert(-1 !== this.obj.indexOf(str, this.obj.length - str.length)
, function() { return 'expected ' + this.inspect + ' to end with ' + should.inspect(str) + (description ? " | " + description : "") }
, function() { return 'expected ' + this.inspect + ' to not end with ' + should.inspect(str) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
return this;
},
/**
* Assert that `obj` is present via `.indexOf()` or that `obj` contains some sub-object.
*
* @param {*} obj
* @param {String} description
* @api public
*/
include: function(obj, description){
if (!Array.isArray(this.obj) && !util.isString(this.obj)){
var cmp = {};
for (var key in obj) cmp[key] = this.obj[key];
this.assert(
eql(cmp, obj)
, function(){ return 'expected ' + this.inspect + ' to include an object equal to ' + should.inspect(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not include an object equal to ' + should.inspect(obj) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
} else {
this.assert(
~this.obj.indexOf(obj)
, function(){ return 'expected ' + this.inspect + ' to include ' + should.inspect(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not include ' + should.inspect(obj) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
}
return this;
},
/**
* Assert that an object equal to `obj` is present.
*
* @param {Array} obj
* @param {String} description
* @api public
*/
includeEql: function(obj, description){
this.assert(
this.obj.some(function(item) { return eql(obj, item); })
, function(){ return 'expected ' + this.inspect + ' to include an object equal to ' + should.inspect(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not include an object equal to ' + should.inspect(obj) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
return this;
},
/**
* Assert exact keys or inclusion of keys by using
* the `.include` modifier.
*
* @param {Array|String ...} keys
* @api public
*/
keys: function(keys){
var str
, ok = true;
keys = keys instanceof Array
? keys
: Array.prototype.slice.call(arguments);
if (!keys.length) throw new Error('keys required');
var actual = Object.keys(this.obj)
, len = keys.length;
// make sure they're all present
ok = keys.every(function(key){
return ~actual.indexOf(key);