-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.ts
More file actions
90 lines (83 loc) · 2.79 KB
/
errors_test.ts
File metadata and controls
90 lines (83 loc) · 2.79 KB
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
import { assertEquals, assertInstanceOf } from "@std/assert";
import { ClientError } from "@probitas/client";
import { GraphqlExecutionError, GraphqlNetworkError } from "./errors.ts";
import type { GraphqlErrorItem } from "./types.ts";
Deno.test("GraphqlNetworkError", async (t) => {
await t.step("extends ClientError", () => {
const error = new GraphqlNetworkError("connection refused");
assertInstanceOf(error, ClientError);
assertInstanceOf(error, GraphqlNetworkError);
});
await t.step("has correct properties", () => {
const error = new GraphqlNetworkError("connection refused");
assertEquals(error.name, "GraphqlNetworkError");
assertEquals(error.kind, "network");
assertEquals(error.message, "connection refused");
});
await t.step("supports cause option", () => {
const cause = new TypeError("fetch failed");
const error = new GraphqlNetworkError("network error", { cause });
assertEquals(error.cause, cause);
});
});
Deno.test("GraphqlExecutionError", async (t) => {
await t.step("extends ClientError", () => {
const errors: GraphqlErrorItem[] = [
{
message: "Resolver failed",
locations: null,
path: null,
extensions: null,
},
];
const error = new GraphqlExecutionError(errors);
assertInstanceOf(error, ClientError);
assertInstanceOf(error, GraphqlExecutionError);
});
await t.step("has correct properties", () => {
const errors: GraphqlErrorItem[] = [
{
message: "User not found",
locations: null,
path: null,
extensions: null,
},
];
const error = new GraphqlExecutionError(errors);
assertEquals(error.name, "GraphqlExecutionError");
assertEquals(error.kind, "graphql");
assertEquals(error.errors, errors);
assertEquals(
error.message.startsWith("GraphQL execution failed:\n\n"),
true,
);
assertEquals(error.message.includes("User not found"), true);
});
await t.step("formats multiple errors", () => {
const errors: GraphqlErrorItem[] = [
{
message: "Field not found",
locations: null,
path: null,
extensions: null,
},
{
message: "Access denied",
locations: null,
path: null,
extensions: null,
},
];
const error = new GraphqlExecutionError(errors);
assertEquals(error.message.includes("Field not found"), true);
assertEquals(error.message.includes("Access denied"), true);
});
await t.step("supports cause option", () => {
const cause = new Error("underlying error");
const errors: GraphqlErrorItem[] = [
{ message: "error", locations: null, path: null, extensions: null },
];
const error = new GraphqlExecutionError(errors, { cause });
assertEquals(error.cause, cause);
});
});