coler-j
coler-j

Reputation: 2109

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

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?

Upvotes: 7

Views: 3037

Answers (1)

karczewski
karczewski

Reputation: 106

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.

Upvotes: 5

Related Questions