forked from ErickWendel/semana-javascript-expert06
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testUtil.js
53 lines (46 loc) · 983 Bytes
/
testUtil.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
41
42
43
44
45
46
47
48
49
50
51
52
53
import {
jest
} from '@jest/globals'
import {
Readable,
Writable
} from 'stream'
export default class TestUtil {
static generateReadableStream(data) {
return new Readable({
read() {
for(const item of data) {
this.push(item)
}
this.push(null)
}
})
}
static generateWritableStream(onData) {
return new Writable({
write(chunk, enc, cb) {
onData(chunk)
cb(null, chunk)
}
})
}
static defaultHandleParams() {
const requestStream = TestUtil.generateReadableStream(['body da requisicao'])
const response = TestUtil.generateWritableStream(() => {})
const data = {
request: Object.assign(requestStream, {
headers: {},
method: '',
url: ''
}),
response: Object.assign(response, {
writeHead: jest.fn(),
end: jest.fn()
})
}
return {
values: () => Object.values(data),
...data,
}
}
}