@@ -101,6 +101,7 @@ function wrapAssertFn(assertFn) {
101
101
* .expect('Content-Type', 'application/json')
102
102
* .expect('Content-Type', 'application/json', fn)
103
103
* .expect(fn)
104
+ * .expect([200, 404])
104
105
*
105
106
* @return {Test }
106
107
* @api public
@@ -125,6 +126,12 @@ Test.prototype.expect = function(a, b, c) {
125
126
return this ;
126
127
}
127
128
129
+ // multiple statuses
130
+ if ( Array . isArray ( a ) ) {
131
+ this . _asserts . push ( wrapAssertFn ( this . _assertStatusArray . bind ( this , a ) ) ) ;
132
+ return this ;
133
+ }
134
+
128
135
// header field
129
136
if ( typeof b === 'string' || typeof b === 'number' || b instanceof RegExp ) {
130
137
this . _asserts . push ( wrapAssertFn ( this . _assertHeader . bind ( this , { name : '' + a , value : b } ) ) ) ;
@@ -297,6 +304,25 @@ Test.prototype._assertStatus = function(status, res) {
297
304
}
298
305
} ;
299
306
307
+ /**
308
+ * Perform assertions on the response status and return an Error upon failure.
309
+ *
310
+ * @param {Array<Number> } statusArray
311
+ * @param {Response } res
312
+ * @return {?Error }
313
+ * @api private
314
+ */
315
+
316
+ Test . prototype . _assertStatusArray = function ( statusArray , res ) {
317
+ var b ;
318
+ var expectedList ;
319
+ if ( ! statusArray . includes ( res . status ) ) {
320
+ b = http . STATUS_CODES [ res . status ] ;
321
+ expectedList = statusArray . join ( ', ' ) ;
322
+ return new Error ( 'expected one of "' + expectedList + '", got ' + res . status + ' "' + b + '"' ) ;
323
+ }
324
+ } ;
325
+
300
326
/**
301
327
* Performs an assertion by calling a function and return an Error upon failure.
302
328
*
0 commit comments