graphql#GraphQLError JavaScript Examples

The following examples show how to use graphql#GraphQLError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProductsList.spec.js    From ReactNativeApolloOnlineStore with MIT License 4 votes vote down vote up
describe('ProductsList', () => {
  it('shows loading', () => {
    const component = renderer.create(
      <MockedProvider>
        <ProductsList />
      </MockedProvider>,
    );

    expect(() => component.root.findByType('ActivityIndicator')).not.toThrow();
  });

  it('shows error', async () => {
    const mockedError = {
      request: {
        query: GET_ALL_PRODUCTS,
      },
      // error: new Error('Oops we can not get the products'),
      result: {
        errors: [new GraphQLError('Oops we can not get the products')],
      },
    };
    const component = renderer.create(
      <MockedProvider mocks={[mockedError]} addTypename={false}>
        <ProductsList />
      </MockedProvider>,
    );

    await wait();

    expect(() => {
      component.root.findByProps({
        children: 'GraphQL error: Oops we can not get the products',
      });
    }).not.toThrow();
  });

  it('shows products list', async () => {
    const mockedData = {
      request: {
        query: GET_ALL_PRODUCTS,
      },
      result: {
        data: {
          products: [
            {
              id: '1',
              name: 'Nike II',
              price: 100,
              description: 'Here goes the desc',
              favorite: true,
              thumb: {
                id: '1',
                url: '/uploads/f572595fddfc4eb78eaa4d75e085d1d5.jpg',
              },
            },
            {
              id: '2',
              name: 'Nike Pro',
              price: 190,
              description: 'I am nike pro  ?',
              favorite: false,
              thumb: {
                id: '2',
                url: '/uploads/aa6a78cf1e6e4a0292f103b53570f8bc.jpg',
              },
            },
          ],
        },
      },
    };
    const component = renderer.create(
      <MockedProvider mocks={[mockedData]} addTypename={false}>
        <ProductsList />
      </MockedProvider>,
    );

    await wait();

    console.log(component.toJSON());
    expect(() => {
      component.root.findByProps({
        children: 'Nike II',
      });
    }).not.toThrow();
    expect(() => {
      component.root.findByProps({
        children: 'Nike Prcs',
      });
    }).not.toThrow();
  });
});