-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmock-scope.test.ts
69 lines (63 loc) · 2.14 KB
/
mock-scope.test.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
import * as blocks from "https://deno.land/[email protected]/testing/bdd.ts";
import * as asserts from "https://deno.land/[email protected]/testing/asserts.ts";
import { InvalidArgumentError, MockRequest, MockScope } from "./mod.ts";
blocks.describe("MockScope", () => {
blocks.describe("delay", () => {
[
{
name: "should throw an error if a negative delay is passed",
delay: -1,
error: "Invalid delay: waitInMs must be a valid integer > 0",
},
{
name: "should throw an error if a zero delay is passed",
delay: 0,
error: "Invalid delay: waitInMs must be a valid integer > 0",
},
{
name: "should throw an error if a non-integer delay is passed",
delay: 1.1,
error: "Invalid delay: waitInMs must be a valid integer > 0",
},
].forEach((test) => {
blocks.it(test.name, () => {
// Arrange
const mockScope = new MockScope({} as unknown as MockRequest);
// Act
const error = asserts.assertThrows(() => mockScope.delay(test.delay));
// Assert
asserts.assertIsError(error, InvalidArgumentError, test.error);
});
});
});
blocks.describe("times", () => {
[
{
name: "should throw an error if a negative input is passed",
repeatTimes: -1,
error: "Invalid times input: repeatTimes must be a valid integer > 0",
},
{
name: "should throw an error if a zero input is passed",
repeatTimes: 0,
error: "Invalid times input: repeatTimes must be a valid integer > 0",
},
{
name: "should throw an error if a non-integer input is passed",
repeatTimes: 1.1,
error: "Invalid times input: repeatTimes must be a valid integer > 0",
},
].forEach((test) => {
blocks.it(test.name, () => {
// Arrange
const mockScope = new MockScope({} as unknown as MockRequest);
// Act
const error = asserts.assertThrows(() =>
mockScope.times(test.repeatTimes)
);
// Assert
asserts.assertIsError(error, InvalidArgumentError, test.error);
});
});
});
});