-
Notifications
You must be signed in to change notification settings - Fork 16
/
frisby.node.txt
138 lines (105 loc) · 7.92 KB
/
frisby.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
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
FRISBY
ALTERNATIVES ==> # - frisby (prefer)
# - uses node-fetch
# - supertest:
# - not maintained
# - uses superagent
# - chai-http:
# - uses superagent
# - Chai-specific
# - a little more features:
# - can assert REQ (not just RES) (not very useful)
# - helper functions to assert redirect status codes, Content-Type [S] and Cookie [S]
VERSION ==> #2.1.2
#Assertions on HTTP response (status, headers, body)
/=+===============================+=\
/ : : \
)==: BASE :==(
\ :_______________________________: /
\=+===============================+=/
FREQ.*()->FREQ #All FREQ methods return FREQ
#Also if FRISBY|FREQ.*(), FRISBY method returns FREQ
FRISBY|FREQ.use(FUNC(FREQ)) #Plugin system.
#Just fires FUNC(FREQ)
/=+===============================+=\
/ : : \
)==: REQUEST :==(
\ :_______________________________: /
\=+===============================+=/
FRISBY|FREQ.fetch('URL'[, OBJ]) #Like fetch(...)
#OBJ (beside regular fetch options):
# - urlEncode true: apply encodeURI() on 'URL'
FRISBY|FREQ. #Same as *.fetch() but:
get|patch|post|put|del[ete](...) # - with OBJ.method
# - apply JSON.stringify() on OBJ.body OBJ2
FRISBY|FREQ.fromJSON(VAL) #Same as *.fetch() but using a fake request:
# - url '/'
# - status 200
# - headers Content-Type: application/json [S]
# - body VAL
FRISBY|FREQ.options(OBJ) #Same as *.fetch() but with options OBJ
FRISBY.globalSetup(OPTS) #OPTS.request are default fetch options
FRISBY|FREQ.setup(OPTS[, BOOL]) #Default are:
# - credentials 'include'
# - headers Content-Type: application/json [C], User-Agent: frisby/VERSION
# - timeout 5000
#If BOOL true, replace instead of deep merge.
FRISBY.baseUrl('URL') #For relative URLs
#Can also use OPTS.request.baseUrl 'URL'
FRISBY.getBaseUrl()->'URL' #
FRISBY|FREQ.timeout(NUM) #
FREQ.timeout()->NUM #
/=+===============================+=\
/ : : \
)==: RESPONSE :==(
\ :_______________________________: /
\=+===============================+=/
FREQ.promise()->PROMISE #fetch()'s PROMISE
FREQ.then|catch(...) #Same as FREQ.promise().then|catch(...)
#Except default error handler: console.log() the JSON response
#(unless OPTS.request.inspectOnFailure false)
FREQ.done(FUNC) #Same as FREQ.then(() => FUNC())
/=+===============================+=\
/ : : \
)==: DEBUGGING :==(
\ :_______________________________: /
\=+===============================+=/
FREQ.inspectRequest() #console.log() request
FREQ.inspectRequestHeaders() #console.log() request headers
FREQ.inspectResponse() #console.log() response
FREQ.inspectStatus() #console.log() response status
FREQ.inspectHeaders() #console.log() response headers
FREQ.inspectBody() #console.log() response body
FREQ.inspectJSON() #console.log() response body, as JSON
/=+===============================+=\
/ : : \
)==: ASSERTIONS :==(
\ :_______________________________: /
\=+===============================+=/
FREQ.expect(...) #Throw ERROR if expectation on fetch()'s RES not met.
#If fetch()'s PROMISE was rejected, expect[Not]() will not be checked,
#i.e. PROMISE should be returned in the test's it()
FREQ.expectNot(...) #Inverse
FREQ.expect(FUNC(RES)) #Asserts RES
FREQ.expect('status', NUM) #Asserts RES.status
FREQ.expect
('header', 'VAR'[, VAL|REGEXP]) #Asserts RES.get('VAR'), case-insensitive.
FREQ.expect
('bodyContains', STR|REGEXP) #Asserts stringified RES.body
FREQ.json(['VARR',] VAL) #Asserts RES.body as a JSON value
#If VAL is OBJ|ARR, check it is a subset
#VAL can be REGEXP as well
#Otherwise, check it is equal
#VARR is path within body. It can contain:
# - & for "all OBJ keys"
# - * for "all OBJ|ARR indices"
# - ? for "at least one OBJ|ARR key"
FREQ.jsonStrict(['VARR',] VAL) #Same but does a deepEqual()
FREQ.jsonTypes[Strict] #Same but using JOI.validate(RES.body, SCHEMA) (see its doc)
(['VARR',] SCHEMA) #Uses OPTS.allowUnknown true (unknown properties) unless "Strict"
FRISBY|FREQ.addExpectHandler
('NAME', FUNC(RES, ...)) #Add custom FREQ.expect('NAME', ...)
FRISBY|FREQ.removeExpectHandler
('NAME') #