Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
How do you test cache only queries in apollo?

I have a query like this:

  const { data } = useQuery(GET_STUFF, {
    fetchPolicy: "cache-only",
  })

This works fine in the code. In the tests data is undefined

but I've mocked it like so:

  {
    request: {
      query: GET_STUFF,
    },
    result: {
      data: {
        __a: {
          id: "12",
        },
      },
    },
  },

but when I change fetchPolicy to fetchPolicy: "network-only" it then comes through as the expected result.

The problem also is I can't also pass cache into <MockedProvider /> as I have queries on that page that also use network-only

How do I solve this or throw stuff automatically into the cache?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!