/
locatedError-test.ts
54 lines (45 loc) · 1.32 KB
/
locatedError-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
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { GraphQLError } from '../GraphQLError';
import { locatedError } from '../locatedError';
describe('locatedError', () => {
it('passes GraphQLError through', () => {
const e = new GraphQLError('msg', null, null, null, [
'path',
3,
'to',
'field',
]);
expect(locatedError(e, [], [])).to.deep.equal(e);
});
it('wraps non-errors', () => {
const testObject = Object.freeze({});
const error = locatedError(testObject, [], []);
expect(error).to.be.instanceOf(GraphQLError);
expect(error.originalError).to.include({
name: 'NonErrorThrown',
thrownValue: testObject,
});
});
it('passes GraphQLError-ish through', () => {
const e = new Error();
// @ts-expect-error
e.locations = [];
// @ts-expect-error
e.path = [];
// @ts-expect-error
e.nodes = [];
// @ts-expect-error
e.source = null;
// @ts-expect-error
e.positions = [];
e.name = 'GraphQLError';
expect(locatedError(e, [], [])).to.deep.equal(e);
});
it('does not pass through elasticsearch-like errors', () => {
const e = new Error('I am from elasticsearch');
// @ts-expect-error
e.path = '/something/feed/_search';
expect(locatedError(e, [], [])).to.not.deep.equal(e);
});
});