-
Notifications
You must be signed in to change notification settings - Fork 0
/
full-http-control.test.js
40 lines (37 loc) · 1.01 KB
/
full-http-control.test.js
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
'use strict'
const tape = require('tape')
const fullHttpControl = require('./full-http-control')
const contextMock = {}
const reqMock = {}
const responseMock = (t, expected) => {
return {
writeHead: (statusCode, contentType) => {
t.equal(
expected.statusCode,
statusCode,
`Assert expected: ${expected.statusCode} matches actual: ${statusCode}`
)
t.deepEquals(
expected.contentType,
contentType,
`Assert expected: ${JSON.stringify(expected.contentType)} matches actual: ${JSON.stringify(contentType)}`
)
},
end: (response) => {
t.equal(
expected.response,
response,
`Assert expected: ${expected.response} matches actual: ${response}`
)
}
}
}
tape('Full http control test cases', (t) => {
const expected = {
statusCode: 200,
contentType: { 'Content-Type': 'text/html ' },
response: '<h1>Hello, world!</h1>'
}
fullHttpControl(contextMock, reqMock, responseMock(t, expected))
t.end()
})