Skip to content

Commit

Permalink
Fix useQuery test to provide missing result.data.
Browse files Browse the repository at this point in the history
This test was previously delivering a `loading: false` result with
neither `data` nor `error` defined, and now it delivers the correct
data. Progress!
  • Loading branch information
benjamn committed Aug 13, 2021
1 parent 47dd5fe commit b5d5e58
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/react/hooks/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { ApolloLink } from '../../../link/core';
import { itAsync, MockLink, MockedProvider, mockSingleLink } from '../../../testing';
import { useQuery } from '../useQuery';
import { useMutation } from '../useMutation';
import { invariant } from 'ts-invariant';

describe('useQuery Hook', () => {
describe('General use', () => {
Expand Down Expand Up @@ -2438,7 +2437,6 @@ describe('useQuery Hook', () => {
describe('Missing Fields', () => {
it('should log debug messages about MissingFieldErrors from the cache', async () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const debugSpy = jest.spyOn(invariant, 'debug').mockImplementation(() => {});

const carQuery: DocumentNode = gql`
query cars($id: Int) {
Expand Down Expand Up @@ -2488,15 +2486,8 @@ describe('useQuery Hook', () => {
expect(result.current.error).toBe(undefined);
await waitForNextUpdate();
expect(result.current.loading).toBe(false);
expect(result.current.data).toBe(undefined);

expect(result.current.data).toEqual(carData);
expect(result.current.error).toBeUndefined();
expect(debugSpy).toHaveBeenCalledTimes(1);
expect(debugSpy).toHaveBeenLastCalledWith(
"Missing cache result fields: cars.0.vin",
[new Error("Can't find field 'vin' on Car:1 object")]
);
debugSpy.mockRestore();

expect(errorSpy).toHaveBeenCalledTimes(1);
expect(errorSpy).toHaveBeenLastCalledWith(
Expand Down

0 comments on commit b5d5e58

Please sign in to comment.