Skip to content

Graphql Variable Validation with Jest #501

Answered by kettanaito
birdwell asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, @birdwell.

MSW doesn't encourage assertion on request data, as it may often be asserted by UI instead. The input data that we sent to the server is often directly or indirectly present in the response that we use to render the UI. If that's possible, strongly consider basing your assertion on the UI that gets rendered by your query response.

At the same time, we understand there may be cases when the recommendation above is not fully applicable. You can still issue regular assertions within the response resolver:

graphql.query<SaveContent, SaveContentVariables>('SaveContent', (req, res, ctx) => {
  expect(req.variables).toEqual({ id: 'abc-123' })

  return res(
    ctx.data({
      s…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@birdwell
Comment options

@kettanaito
Comment options

Answer selected by birdwell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants