/
formatError-test.ts
58 lines (49 loc) · 1.41 KB
/
formatError-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
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { formatError } from '../formatError';
import { GraphQLError } from '../GraphQLError';
describe('formatError: default error formatter', () => {
it('uses default message', () => {
// @ts-expect-error
const e = new GraphQLError();
expect(formatError(e)).to.deep.equal({
message: 'An unknown error occurred.',
path: undefined,
locations: undefined,
});
});
it('includes path', () => {
const e = new GraphQLError('msg', null, null, null, [
'path',
3,
'to',
'field',
]);
expect(formatError(e)).to.deep.equal({
message: 'msg',
locations: undefined,
path: ['path', 3, 'to', 'field'],
});
});
it('includes extension fields', () => {
const e = new GraphQLError('msg', null, null, null, null, null, {
foo: 'bar',
});
expect(formatError(e)).to.deep.equal({
message: 'msg',
locations: undefined,
path: undefined,
extensions: { foo: 'bar' },
});
});
it('rejects null and undefined errors', () => {
// TODO ts-expect-error (formatError expects a value)
expect(() => formatError(undefined)).to.throw(
'Received null or undefined error.',
);
// TODO ts-expect-error (formatError expects a value)
expect(() => formatError(null)).to.throw(
'Received null or undefined error.',
);
});
});