UNPKG

989 BJavaScriptView Raw
1import { ApolloError } from 'apollo-server-core';
2import getErrorDetail from './getErrorDetail';
3
4describe('GetErrorDetail', () => {
5 describe('codes', () => {
6 it('returns an empty array if given an empty object', () => {
7 const codes = getErrorDetail({}).codes;
8
9 expect(codes).toEqual([]);
10 });
11 it('returns an array of codes, filtering out errors with no graphQLErrors attached', () => {
12 const codes = getErrorDetail(error).codes;
13
14 expect(codes).toEqual(
15 expect.arrayContaining([
16 'UnableToSubscribeToNewsletter',
17 'SomeOtherError'
18 ])
19 );
20 expect(codes).toHaveLength(2);
21 });
22 });
23});
24
25const graphQLErrors = [
26 {
27 message: '',
28 extensions: {
29 code: 'UnableToSubscribeToNewsletter'
30 }
31 },
32 {
33 message: '',
34 extensions: {
35 code: 'SomeOtherError'
36 }
37 },
38 {
39 message: 'wow'
40 }
41];
42
43// Create a mock ApolloError
44const error = new ApolloError(null, null, { graphQLErrors });