forked from nodejs/undici
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock-scope.js
68 lines (60 loc) · 2.22 KB
/
mock-scope.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict'
const { tspl } = require('@matteo.collina/tspl')
const { test, describe } = require('node:test')
const { MockScope } = require('../lib/mock/mock-interceptor')
const { InvalidArgumentError } = require('../lib/core/errors')
describe('MockScope - delay', () => {
test('should return MockScope', t => {
t = tspl(t, { plan: 1 })
const mockScope = new MockScope({
path: '',
method: ''
}, [])
const result = mockScope.delay(200)
t.ok(result instanceof MockScope)
})
test('should error if passed options invalid', t => {
t = tspl(t, { plan: 4 })
const mockScope = new MockScope({
path: '',
method: ''
}, [])
t.throws(() => mockScope.delay(), new InvalidArgumentError('waitInMs must be a valid integer > 0'))
t.throws(() => mockScope.delay(200.1), new InvalidArgumentError('waitInMs must be a valid integer > 0'))
t.throws(() => mockScope.delay(0), new InvalidArgumentError('waitInMs must be a valid integer > 0'))
t.throws(() => mockScope.delay(-1), new InvalidArgumentError('waitInMs must be a valid integer > 0'))
})
})
describe('MockScope - persist', () => {
test('should return MockScope', t => {
t = tspl(t, { plan: 1 })
const mockScope = new MockScope({
path: '',
method: ''
}, [])
const result = mockScope.persist()
t.ok(result instanceof MockScope)
})
})
describe('MockScope - times', t => {
test('should return MockScope', t => {
t = tspl(t, { plan: 1 })
const mockScope = new MockScope({
path: '',
method: ''
}, [])
const result = mockScope.times(200)
t.ok(result instanceof MockScope)
})
test('should error if passed options invalid', t => {
t = tspl(t, { plan: 4 })
const mockScope = new MockScope({
path: '',
method: ''
}, [])
t.throws(() => mockScope.times(), new InvalidArgumentError('repeatTimes must be a valid integer > 0'))
t.throws(() => mockScope.times(200.1), new InvalidArgumentError('repeatTimes must be a valid integer > 0'))
t.throws(() => mockScope.times(0), new InvalidArgumentError('repeatTimes must be a valid integer > 0'))
t.throws(() => mockScope.times(-1), new InvalidArgumentError('repeatTimes must be a valid integer > 0'))
})
})