Skip to content

Commit

Permalink
Fix LikeButton test
Browse files Browse the repository at this point in the history
  • Loading branch information
sandercamp committed Aug 18, 2023
1 parent 6da2907 commit 2fb3af0
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/modules/feed/components/Transaction/LikeButton.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '../../../../spec_helper';
import LikeButton, { MUTATION_TOGGLE_LIKE } from './LikeButton';
import { FragmentPostResult, GET_GOAL_PERCENTAGE, GET_POSTS } from '../../queries';
import { render, screen, waitFor } from '@testing-library/react';
import {act, render, screen, waitFor} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { InMemoryCache } from '@apollo/client';

Expand Down Expand Up @@ -42,7 +42,7 @@ const mocks = [
{
request: {
query: MUTATION_TOGGLE_LIKE,
variables: { id: '1' },
variables: { id: "1" },
},
result: () => {
mutationCalled = true;
Expand Down Expand Up @@ -112,13 +112,31 @@ describe('<LikeButton />', () => {
});

it('calls the mutation', async () => {
const cache = new InMemoryCache({ addTypename: false });
const cache = new InMemoryCache({
addTypename: false,
typePolicies: {
Query: {
fields: {
teamById: {
read(_, { args, toReference }) {
return toReference({
__typename: 'Team',
id: args?.id,
});
}
}
}
}
}
});

cache.writeQuery({
query: GET_POSTS,
variables: { team_id: "1" },
data: {
teamById: {
id: "1",
__typename: 'Team',
posts: {
edges: [
{
Expand All @@ -142,10 +160,11 @@ describe('<LikeButton />', () => {
);

const button = screen.getByTestId("like-button");
userEvent.click(button);

await waitFor(() => {
expect(mutationCalled).toBe(true);
});
await act(async () =>
userEvent.click(button)
);

expect(mutationCalled).toBe(true);
});
});

0 comments on commit 2fb3af0

Please sign in to comment.