MCPcopy
hub / github.com/forwardemail/supertest / expect

Method expect

lib/test.js:89–124  ·  view source on GitHub ↗

* Expectations: * * .expect(200) * .expect(200, fn) * .expect(200, body) * .expect('Some body') * .expect('Some body', fn) * .expect(['json array body', { key: 'val' }]) * .expect('Content-Type', 'application/json') * .expect('Content-Type', 'application/js

(a, b, c)

Source from the content-addressed store, hash-verified

87 * @api public
88 */
89 expect(a, b, c) {
90 // callback
91 if (typeof a === 'function') {
92 this._asserts.push(wrapAssertFn(a));
93 return this;
94 }
95 if (typeof b === 'function') this.end(b);
96 if (typeof c === 'function') this.end(c);
97
98 // status
99 if (typeof a === 'number') {
100 this._asserts.push(wrapAssertFn(this._assertStatus.bind(this, a)));
101 // body
102 if (typeof b !== 'function' && arguments.length > 1) {
103 this._asserts.push(wrapAssertFn(this._assertBody.bind(this, b)));
104 }
105 return this;
106 }
107
108 // multiple statuses
109 if (Array.isArray(a) && a.length > 0 && a.every(val => typeof val === 'number')) {
110 this._asserts.push(wrapAssertFn(this._assertStatusArray.bind(this, a)));
111 return this;
112 }
113
114 // header field
115 if (typeof b === 'string' || typeof b === 'number' || b instanceof RegExp) {
116 this._asserts.push(wrapAssertFn(this._assertHeader.bind(this, { name: '' + a, value: b })));
117 return this;
118 }
119
120 // body
121 this._asserts.push(wrapAssertFn(this._assertBody.bind(this, a)));
122
123 return this;
124 }
125
126 /**
127 * Defer invoking superagent's `.end()` until

Callers 3

issue-fixes.jsFile · 0.80
supertest.jsFile · 0.80
cookies.jsFile · 0.80

Calls 2

endMethod · 0.95
wrapAssertFnFunction · 0.85

Tested by

no test coverage detected