How to test a component that uses an apollo client Reactive Var

Viewed 1180

How do you unit test (with jest and enzyme) a functional component that uses the useReactiveVar hook?

Should I mock the useReactiveVar hook with jest?

1 Answers

you can mock whole apollo client in each test to give different responses. I mean:

jest.mock('@apollo/client', () => ({
    makeVar: () => {
      return {};
    },
    useReactiveVar: () => {
      return { account: { name: 'Test' } };
    },
  }));

But this is helpful only when testing component that use only one reactiveVar at all.

Related