Skip to content

Better way of testing graphql variables #1778

Answered by mattcosta7
zgrybus asked this question in Q&A
Discussion options

You must be logged in to vote

I think there are potentially a few options here. One that could be reasonable for your use case could be something like

it('edits activity', async () => {
    const editActivityMutationCalls = []
    mockedGraphqlServer.use(
      graphql.mutation('EditActivity', (req, res, ctx) => {
        editActivityMutationCalls.push(req.variables)
        return res(ctx.data({ modifyUpdate: { id: req.variables.id } }));
      }),
    );

    const props = produce(initialProps, draftProps => {
      draftProps.onSuccess = jest.fn();
    });
    const { result } = setup(props);

    act(() => {
      result.current.onEditActivity(123, 'my new text');
    });
    expect(editActivityMutationCalls).toHa…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@zgrybus
Comment options

Answer selected by zgrybus
Comment options

You must be logged in to vote
1 reply
@mattcosta7
Comment options

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