Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing/fixture docs #554

Merged
merged 6 commits into from
Feb 25, 2020
Merged

Add testing/fixture docs #554

merged 6 commits into from
Feb 25, 2020

Conversation

andyrichardson
Copy link
Contributor

@andyrichardson andyrichardson commented Feb 20, 2020

About

Docs on how to test + create fixtures with Urql!

It covers

  • Testing calls to the client
  • Forcing states (fetching, response, error, etc)
  • Handling multiple hooks
  • Simulating multiple responses

View markdown

Notes

  • This is intended to cover all the info required to get testing (not a deep dive on how Wonka streams work)
  • The examples use Enzyme mounts but principles apply to any library (including those with generic names)
  • @bstro read my mind - Fix How to write tests with Provider #550

@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2020

💥 No Changeset

Latest commit: 54c9368

Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂

If these changes should be published to npm, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Collaborator

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very good to me! Great work

Copy link
Contributor

@wgolledge wgolledge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome. I'll be reading this more thoroughly myself 😅

@bstro
Copy link

bstro commented Feb 20, 2020

I'm attempting to follow these instructions right now and am finding that <Provider> does not typecheck when I give it the following client object:

const mockClient = {
  executeQuery: () => {},
  executeMutation: () => {},
  executeSubscription: () => {},
}

I am calling Provider like so:

    <Provider value={mockClient}>
      …
    </Provider>

and the typescript error is:

Type '{ executeQuery: () => void; executeMutation: () => void; executeSubscription: () => void; }'
 is missing the following properties from type 'Client':
  url, exchange, suspense, preferGetMethod, and 15 more.  TS2740

@andyrichardson
Copy link
Contributor Author

@bstro this is because the mocks in the example don't match the actual client.

The way to go is to cast this as an any. I'll add a note about this to the docs.

const mockClient: any = {
  executeQuery: () => {},
  executeMutation: () => {},
  executeSubscription: () => {},
}

@kitten kitten merged commit 5cf197a into master Feb 25, 2020
kitten pushed a commit that referenced this pull request Feb 25, 2020
* Add testing docs

* Add testing docs

* Clarify what is react specific

* Update docs/core/testing.md

* Update docs/core/testing.md

* Move Testing to Advanced
@andyrichardson andyrichardson deleted the add-docs branch February 25, 2020 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to write tests with Provider
5 participants