@@ -14,15 +14,15 @@ const { Request } = require('superagent');
14
14
15
15
class Test extends Request {
16
16
/**
17
- * Initialize a new `Test` with the given `app`,
18
- * request `method` and `path`.
19
- *
20
- * @param {Server } app
21
- * @param {String } method
22
- * @param {String } path
23
- * @api public
24
- */
25
- constructor ( app , method , path ) {
17
+ * Initialize a new `Test` with the given `app`,
18
+ * request `method` and `path`.
19
+ *
20
+ * @param {Server } app
21
+ * @param {String } method
22
+ * @param {String } path
23
+ * @api public
24
+ */
25
+ constructor ( app , method , path ) {
26
26
super ( method . toUpperCase ( ) , path ) ;
27
27
28
28
this . redirects ( 0 ) ;
@@ -35,13 +35,13 @@ class Test extends Request {
35
35
}
36
36
37
37
/**
38
- * Returns a URL, extracted from a server.
39
- *
40
- * @param {Server } app
41
- * @param {String } path
42
- * @returns {String } URL address
43
- * @api private
44
- */
38
+ * Returns a URL, extracted from a server.
39
+ *
40
+ * @param {Server } app
41
+ * @param {String } path
42
+ * @returns {String } URL address
43
+ * @api private
44
+ */
45
45
serverAddress ( app , path ) {
46
46
const addr = app . address ( ) ;
47
47
@@ -52,22 +52,22 @@ class Test extends Request {
52
52
}
53
53
54
54
/**
55
- * Expectations:
56
- *
57
- * .expect(200)
58
- * .expect(200, fn)
59
- * .expect(200, body)
60
- * .expect('Some body')
61
- * .expect('Some body', fn)
62
- * .expect(['json array body', { key: 'val' }])
63
- * .expect('Content-Type', 'application/json')
64
- * .expect('Content-Type', 'application/json', fn)
65
- * .expect(fn)
66
- * .expect([200, 404])
67
- *
68
- * @return {Test }
69
- * @api public
70
- */
55
+ * Expectations:
56
+ *
57
+ * .expect(200)
58
+ * .expect(200, fn)
59
+ * .expect(200, body)
60
+ * .expect('Some body')
61
+ * .expect('Some body', fn)
62
+ * .expect(['json array body', { key: 'val' }])
63
+ * .expect('Content-Type', 'application/json')
64
+ * .expect('Content-Type', 'application/json', fn)
65
+ * .expect(fn)
66
+ * .expect([200, 404])
67
+ *
68
+ * @return {Test }
69
+ * @api public
70
+ */
71
71
expect ( a , b , c ) {
72
72
// callback
73
73
if ( typeof a === 'function' ) {
@@ -106,12 +106,12 @@ class Test extends Request {
106
106
}
107
107
108
108
/**
109
- * Defer invoking superagent's `.end()` until
110
- * the server is listening.
111
- *
112
- * @param {Function } fn
113
- * @api public
114
- */
109
+ * Defer invoking superagent's `.end()` until
110
+ * the server is listening.
111
+ *
112
+ * @param {Function } fn
113
+ * @api public
114
+ */
115
115
end ( fn ) {
116
116
const server = this . _server ;
117
117
@@ -129,13 +129,13 @@ class Test extends Request {
129
129
}
130
130
131
131
/**
132
- * Perform assertions and invoke `fn(err, res)`.
133
- *
134
- * @param {?Error } resError
135
- * @param {Response } res
136
- * @param {Function } fn
137
- * @api private
138
- */
132
+ * Perform assertions and invoke `fn(err, res)`.
133
+ *
134
+ * @param {?Error } resError
135
+ * @param {Response } res
136
+ * @param {Function } fn
137
+ * @api private
138
+ */
139
139
assert ( resError , res , fn ) {
140
140
let errorObj ;
141
141
@@ -173,13 +173,25 @@ class Test extends Request {
173
173
}
174
174
175
175
/**
176
- * Perform assertions on a response body and return an Error upon failure.
177
- *
178
- * @param {Mixed } body
179
- * @param {Response } res
180
- * @return {?Error }
181
- * @api private
182
- */ // eslint-disable-next-line class-methods-use-this
176
+ * Adds a set Authorization Bearer
177
+ *
178
+ * @param {Bearer } Bearer Token
179
+ * Shortcut for .set('Authorization', `Bearer ${token}`)
180
+ */
181
+
182
+ bearer ( token ) {
183
+ this . set ( 'Authorization' , `Bearer ${ token } ` ) ;
184
+ return this ;
185
+ }
186
+
187
+ /**
188
+ * Perform assertions on a response body and return an Error upon failure.
189
+ *
190
+ * @param {Mixed } body
191
+ * @param {Response } res
192
+ * @return {?Error }
193
+ * @api private
194
+ */ // eslint-disable-next-line class-methods-use-this
183
195
_assertBody ( body , res ) {
184
196
const isRegexp = body instanceof RegExp ;
185
197
@@ -209,13 +221,13 @@ class Test extends Request {
209
221
}
210
222
211
223
/**
212
- * Perform assertions on a response header and return an Error upon failure.
213
- *
214
- * @param {Object } header
215
- * @param {Response } res
216
- * @return {?Error }
217
- * @api private
218
- */ // eslint-disable-next-line class-methods-use-this
224
+ * Perform assertions on a response header and return an Error upon failure.
225
+ *
226
+ * @param {Object } header
227
+ * @param {Response } res
228
+ * @return {?Error }
229
+ * @api private
230
+ */ // eslint-disable-next-line class-methods-use-this
219
231
_assertHeader ( header , res ) {
220
232
const field = header . name ;
221
233
const actual = res . header [ field . toLowerCase ( ) ] ;
@@ -238,13 +250,13 @@ class Test extends Request {
238
250
}
239
251
240
252
/**
241
- * Perform assertions on the response status and return an Error upon failure.
242
- *
243
- * @param {Number } status
244
- * @param {Response } res
245
- * @return {?Error }
246
- * @api private
247
- */ // eslint-disable-next-line class-methods-use-this
253
+ * Perform assertions on the response status and return an Error upon failure.
254
+ *
255
+ * @param {Number } status
256
+ * @param {Response } res
257
+ * @return {?Error }
258
+ * @api private
259
+ */ // eslint-disable-next-line class-methods-use-this
248
260
_assertStatus ( status , res ) {
249
261
if ( res . status !== status ) {
250
262
const a = STATUS_CODES [ status ] ;
@@ -254,13 +266,13 @@ class Test extends Request {
254
266
}
255
267
256
268
/**
257
- * Perform assertions on the response status and return an Error upon failure.
258
- *
259
- * @param {Array<Number> } statusArray
260
- * @param {Response } res
261
- * @return {?Error }
262
- * @api private
263
- */ // eslint-disable-next-line class-methods-use-this
269
+ * Perform assertions on the response status and return an Error upon failure.
270
+ *
271
+ * @param {Array<Number> } statusArray
272
+ * @param {Response } res
273
+ * @return {?Error }
274
+ * @api private
275
+ */ // eslint-disable-next-line class-methods-use-this
264
276
_assertStatusArray ( statusArray , res ) {
265
277
if ( ! statusArray . includes ( res . status ) ) {
266
278
const b = STATUS_CODES [ res . status ] ;
@@ -272,13 +284,13 @@ class Test extends Request {
272
284
}
273
285
274
286
/**
275
- * Performs an assertion by calling a function and return an Error upon failure.
276
- *
277
- * @param {Function } fn
278
- * @param {Response } res
279
- * @return {?Error }
280
- * @api private
281
- */ // eslint-disable-next-line class-methods-use-this
287
+ * Performs an assertion by calling a function and return an Error upon failure.
288
+ *
289
+ * @param {Function } fn
290
+ * @param {Response } res
291
+ * @return {?Error }
292
+ * @api private
293
+ */ // eslint-disable-next-line class-methods-use-this
282
294
_assertFunction ( fn , res ) {
283
295
let err ;
284
296
try {
@@ -301,7 +313,7 @@ class Test extends Request {
301
313
function wrapAssertFn ( assertFn ) {
302
314
const savedStack = new Error ( ) . stack . split ( '\n' ) . slice ( 3 ) ;
303
315
304
- return function ( res ) {
316
+ return function ( res ) {
305
317
let badStack ;
306
318
let err ;
307
319
try {
0 commit comments