-
Notifications
You must be signed in to change notification settings - Fork 2k
/
formatError-test.js
60 lines (50 loc) · 1.37 KB
/
formatError-test.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
// @flow strict
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', () => {
// $FlowExpectedError
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', () => {
// $FlowExpectedError
expect(() => formatError(undefined)).to.throw(
'Received null or undefined error.',
);
// $FlowExpectedError
expect(() => formatError(null)).to.throw(
'Received null or undefined error.',
);
});
});