-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsupertest.node.txt
29 lines (23 loc) · 1.66 KB
/
supertest.node.txt
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
┏━━━━━━━━━━━━━━━┓
┃ SUPERTEST ┃
┗━━━━━━━━━━━━━━━┛
ALTERNATIVES ==> #See frisby
VERSION ==> #0.15.0
#SUPERAGENT customized for server-side testing
require("supertest") #Usually called REQUEST
REQUST[.agent](DOMAIN_URL|APP) #Returns SUPERAGENT REQUEST, augmented with some functions.
#If Express APP, deduces DOMAIN_URL.
#Use ".agent" if cookies
REQUEST.expect
(HEADER_STR, REGEXP|STR) #Expectations should be at end of chain.
REQUEST.expect([STATUS_UINT, ]
[BODY_OBJ|STR|REGEXP]) #
REQUEST.expect(FUNC(RES)) #If error, should return|throw STR. Otherwise nothing
REQUEST.end #ERROR is not null if expectations failed, so can be used as async callback to Mocha.
(FUNC2(ERROR, RESPONSE)) #Can instead:
# - pass FUNC2 as last argument to expect() (does not work with expect(FUNC))
# Example: it( STR, function(done) { REQUEST.get(URL).expect(..., done); } );
## - if require("supertest-as-promised") (1.0.0) instead of require("supertest"),
## REQUEST.expect() returns PROMISE:
## - only REQUEST.then(...), resolved with RESPONSE or rejected with ERROR
## - can return REQUEST.expect() in a test case if using CHAI-AS-PROMISED