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

Custom mutation mocking fails #527

Open
dovranJorayev opened this issue Jan 28, 2025 · 0 comments
Open

Custom mutation mocking fails #527

dovranJorayev opened this issue Jan 28, 2025 · 0 comments

Comments

@dovranJorayev
Copy link

dovranJorayev commented Jan 28, 2025

Mocking of custom mutations created via createMutation factory is impossible to mock while createJsonMutation instance is mocking good.

const customMutation = createMutation({
  effect: createEffect(async () => ({
    fileUrl: 'mock-url-valid-image.jpg',
  })),
  contract: zodContract(MutationDataSchema),
});

  it('json query should be mocked even if mutation also been mocked', async () => {
    const scope = fork({
      handlers: [
        [
          jsonQuery.__.executeFx,
          () =>
            Promise.resolve({
              id: 1,
              name: 'test',
            } satisfies QueryData),
        ],
        // If comment this test passes
        [
          customMutation.__.executeFx,
          () =>
            Promise.resolve({
              fileUrl: 'mock-url-valid-image.jpg',
            }),
        ],
      ],
    });

    await allSettled(jsonQuery.start, { scope });

    expect(scope.getState(jsonQuery.$error)).toBeNull();
    expect(scope.getState(jsonQuery.$data)).toEqual({
      id: 1,
      name: 'test',
    });
  });

Also there are other cases described in stackblitz

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

No branches or pull requests

1 participant