-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGraphQLAggregateError.test.mjs
114 lines (104 loc) · 2.9 KB
/
GraphQLAggregateError.test.mjs
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// @ts-check
import { deepStrictEqual, ok, strictEqual, throws } from "node:assert";
import { GraphQLError } from "graphql";
import GraphQLAggregateError from "./GraphQLAggregateError.mjs";
/**
* Adds `GraphQLAggregateError` tests.
* @param {import("test-director").default} tests Test director.
*/
export default (tests) => {
tests.add(
"`GraphQLAggregateError` constructor, argument 1 `errors` not an array.",
() => {
throws(() => {
new GraphQLAggregateError(
// @ts-expect-error Testing invalid.
true,
"",
200,
true
);
}, new TypeError("Argument 1 `errors` must be an array."));
}
);
tests.add(
"`GraphQLAggregateError` constructor, argument 1 `errors` array containing a non `GraphQLError` instance.",
() => {
throws(() => {
new GraphQLAggregateError(
[
new GraphQLError("A"),
// @ts-expect-error Testing invalid.
true,
],
"",
200,
true
);
}, new TypeError("Argument 1 `errors` must be an array containing only `GraphQLError` instances."));
}
);
tests.add(
"`GraphQLAggregateError` constructor, argument 2 `message` not a string.",
() => {
throws(() => {
new GraphQLAggregateError(
[],
// @ts-expect-error Testing invalid.
true,
200,
true
);
}, new TypeError("Argument 2 `message` must be a string."));
}
);
tests.add(
"`GraphQLAggregateError` constructor, argument 3 `status` not a number.",
() => {
throws(() => {
new GraphQLAggregateError(
[],
"",
// @ts-expect-error Testing invalid.
true,
true
);
}, new TypeError("Argument 3 `status` must be a number."));
}
);
tests.add(
"`GraphQLAggregateError` constructor, argument 4 `expose` not a boolean.",
() => {
throws(() => {
new GraphQLAggregateError(
[],
"",
200,
// @ts-expect-error Testing invalid.
1
);
}, new TypeError("Argument 4 `expose` must be a boolean."));
}
);
tests.add("`GraphQLAggregateError` constructor, valid.", () => {
const errors = Object.freeze([
new GraphQLError("A"),
new GraphQLError("B"),
]);
const message = "abc";
const status = 200;
const expose = true;
const graphqlAggregateError = new GraphQLAggregateError(
errors,
message,
status,
expose
);
ok(graphqlAggregateError instanceof Error);
strictEqual(graphqlAggregateError.name, "GraphQLAggregateError");
deepStrictEqual(graphqlAggregateError.message, message);
deepStrictEqual(graphqlAggregateError.errors, errors);
strictEqual(graphqlAggregateError.status, status);
strictEqual(graphqlAggregateError.expose, expose);
});
};