-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
static-response-utils_spec.ts
78 lines (60 loc) · 2.46 KB
/
static-response-utils_spec.ts
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
const {
getBackendStaticResponse,
} = require('../../../../src/cy/net-stubbing/static-response-utils')
describe('driver/src/cy/net-stubbing/static-response-utils', () => {
describe('.getBackendStaticResponse', () => {
describe('delay', () => {
it('does not set delay when delayMS is not provided', () => {
const staticResponse = getBackendStaticResponse({})
expect(staticResponse).to.not.have.property('delay')
})
it('sets delay', () => {
const staticResponse = getBackendStaticResponse({ delayMs: 200 })
expect(staticResponse).to.have.property('delay', 200)
})
})
describe('fixtures', () => {
it('does not set fixtures data when fixtures string is not provided', () => {
const staticResponse = getBackendStaticResponse({})
expect(staticResponse).to.not.have.property('fixtures')
})
it('parses fixture string without file encoding', () => {
const staticResponse = getBackendStaticResponse({ fixture: 'file.html' })
expect(staticResponse.fixture).to.deep.equal({
filePath: 'file.html',
encoding: undefined,
})
})
it('parses fixture string with file encoding', () => {
const staticResponse = getBackendStaticResponse({ fixture: 'file.html,utf8' })
expect(staticResponse.fixture).to.deep.equal({
filePath: 'file.html',
encoding: 'utf8',
})
})
it('parses fixture string with file encoding set as null to indicate Buffer', () => {
const staticResponse = getBackendStaticResponse({ fixture: 'file.html,null' })
expect(staticResponse.fixture).to.deep.equal({
filePath: 'file.html',
encoding: null,
})
})
})
describe('body', () => {
it('does not set body when body is undefined', () => {
const staticResponse = getBackendStaticResponse({})
expect(staticResponse).to.not.have.property('body')
})
it('sets body when body is provided as a string', () => {
const staticResponse = getBackendStaticResponse({ body: 'body' })
expect(staticResponse.body).to.eq('body')
})
it('sets body when body is provided as a ArrayBuffer', () => {
const buffer = new ArrayBuffer(8)
const staticResponse = getBackendStaticResponse({ body: buffer })
expect(staticResponse.body).to.be.a('arraybuffer')
expect(staticResponse.body).to.eq(buffer)
})
})
})
})