Urql: How to write tests with Provider

Created on 20 Feb 2020  路  2Comments  路  Source: FormidableLabs/urql

Is there any documentation for how to write tests for components that make calls to useQuery and useMutation?

What should I use in tests since the entire app is wrapped in urql's Provider? In tests, I need access to that context, but I need the ability to provide it mocked data. apollo-client offers a MockedProvider which takes a mocks prop that I can provide mocked data, but I'm not quite sure what to do in the case of urql.

documentation 馃摉

Most helpful comment

Funny (or suspicious) that you should ask this, keep your eyes peeled for new docs on testing some time today.

All 2 comments

Hey @bstro

I鈥檝e heard about this exchange being used to test. This creates your own miniature resolver. I鈥檓 thinking if we can abstract it further but personally I think it鈥檚 a good start.

Hope this helps you out, feel free to express any concerns you have with that approach.

We're also working on integrating a similar solution: https://github.com/FormidableLabs/urql/pull/474

Funny (or suspicious) that you should ask this, keep your eyes peeled for new docs on testing some time today.

Was this page helpful?
0 / 5 - 0 ratings