|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-present, Facebook, Inc. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +import { expect } from 'chai'; |
| 9 | +import { describe, it } from 'mocha'; |
| 10 | + |
| 11 | +import { GraphQLError } from '../../'; |
| 12 | +import { locatedError } from '../locatedError'; |
| 13 | + |
| 14 | +describe('locatedError', () => { |
| 15 | + |
| 16 | + it('passes GraphQLError through', () => { |
| 17 | + const e = new GraphQLError( |
| 18 | + 'msg', |
| 19 | + null, |
| 20 | + null, |
| 21 | + null, |
| 22 | + [ 'path', 3, 'to', 'field' ] |
| 23 | + ); |
| 24 | + |
| 25 | + expect(locatedError(e, [], [])).to.deep.equal(e); |
| 26 | + }); |
| 27 | + |
| 28 | + it('passes GraphQLError-ish through', () => { |
| 29 | + const e = new Error('I have a different prototype chain'); |
| 30 | + e.locations = []; |
| 31 | + e.path = []; |
| 32 | + e.nodes = []; |
| 33 | + e.source = null; |
| 34 | + e.positions = []; |
| 35 | + e.name = 'GraphQLError'; |
| 36 | + |
| 37 | + expect(locatedError(e, [], [])).to.deep.equal(e); |
| 38 | + }); |
| 39 | + |
| 40 | + it('does not pass through elasticsearch-like errors', () => { |
| 41 | + const e = new Error('I am from elasticsearch'); |
| 42 | + e.path = '/something/feed/_search'; |
| 43 | + |
| 44 | + expect(locatedError(e, [], [])).to.not.deep.equal(e); |
| 45 | + }); |
| 46 | + |
| 47 | +}); |
0 commit comments