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 MSW to testing package #687

Merged
merged 1 commit into from
Jun 12, 2020
Merged

Conversation

RobertBroersma
Copy link
Contributor

@peterp I just started playing around with and this tools is totally awesome!

There's probably a lot more magic we can do for users, like providing a default file where users can define default mocks, but I think this is something we can figure out while we implement config extension and that kind of business.

Check this example for how to use: https://github.com/RobertBroersma/redwood-testing/blob/master/web/src/pages/BlogPostPage/BlogPostPage.test.js

It's good that this decouples us from Apollo.

It does add some tiny constraints, like you can't test anonymous GraphQL queries (or at least _I didn't manage to) but I think that could even be a positive as it enforces the better practice of naming your queries.

This should also Just Work™ with mutations but I haven't tested that yet. I got too excited and instantly opened this PR.

@peterp
Copy link
Contributor

peterp commented Jun 12, 2020

Woo hoo! @RobertBroersma this is amazing!

@peterp
Copy link
Contributor

peterp commented Jun 12, 2020

I'm wondering if there's a way to get rid of the "server" part here:

https://github.com/RobertBroersma/redwood-testing/blob/687d1b34f238cc6f627604c3f84d4b1dbd74e794/web/src/pages/BlogPostPage/BlogPostPage.test.js#L7-L20

Could we wrap graphql.query and graphql.mutation and then remove the server.use implementation detail for the user, maybe something like:

export const graphql = {
    query: (name, callback) => {
         return server.use(graphql.query(name, callback))
    },
    mutation: () => { /*...*/}
}

@peterp peterp merged commit 0560ba9 into redwoodjs:master Jun 12, 2020
@peterp peterp added this to the next release milestone Jun 12, 2020
@thedavidprice thedavidprice added this to Done in Testing Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Testing
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants