Skip to content

Commit

Permalink
Update useMutation tests to adjust for changes in render stream library
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Dec 4, 2024
1 parent d9f20bf commit 624b354
Showing 1 changed file with 33 additions and 39 deletions.
72 changes: 33 additions & 39 deletions src/react/hooks/__tests__/useMutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2873,7 +2873,8 @@ describe("data masking", () => {
link: new MockLink(mocks),
});

const { takeSnapshot } = renderHookToSnapshotStream(
using _disabledAct = disableActEnvironment();
const { takeSnapshot } = await renderHookToSnapshotStream(
() => useMutation(mutation),
{
wrapper: ({ children }) => (
Expand All @@ -2888,10 +2889,18 @@ describe("data masking", () => {
expect(result.data).toBeUndefined();
expect(result.error).toBeUndefined();

let promise!: Promise<FetchResult<Mutation>>;
act(() => {
promise = mutate();
});
{
const { data, errors } = await mutate();

expect(data).toEqual({
updateUser: {
__typename: "User",
id: 1,
name: "Test User",
},
});
expect(errors).toBeUndefined();
}

{
const [, result] = await takeSnapshot();
Expand All @@ -2915,19 +2924,6 @@ describe("data masking", () => {
expect(result.error).toBeUndefined();
}

{
const { data, errors } = await promise;

expect(data).toEqual({
updateUser: {
__typename: "User",
id: 1,
name: "Test User",
},
});
expect(errors).toBeUndefined();
}

await expect(takeSnapshot).not.toRerender();
});

Expand Down Expand Up @@ -2977,7 +2973,8 @@ describe("data masking", () => {
link: new MockLink(mocks),
});

const { takeSnapshot } = renderHookToSnapshotStream(
using _disabledAct = disableActEnvironment();
const { takeSnapshot } = await renderHookToSnapshotStream(
() => useMutation(mutation),
{
wrapper: ({ children }) => (
Expand All @@ -2992,10 +2989,19 @@ describe("data masking", () => {
expect(result.data).toBeUndefined();
expect(result.error).toBeUndefined();

let promise!: Promise<FetchResult<Mutation>>;
act(() => {
promise = mutate();
});
{
const { data, errors } = await mutate();

expect(data).toEqual({
updateUser: {
__typename: "User",
id: 1,
name: "Test User",
age: 30,
},
});
expect(errors).toBeUndefined();
}

{
const [, result] = await takeSnapshot();
Expand All @@ -3020,20 +3026,6 @@ describe("data masking", () => {
expect(result.error).toBeUndefined();
}

{
const { data, errors } = await promise;

expect(data).toEqual({
updateUser: {
__typename: "User",
id: 1,
name: "Test User",
age: 30,
},
});
expect(errors).toBeUndefined();
}

await expect(takeSnapshot).not.toRerender();
});

Expand Down Expand Up @@ -3086,7 +3078,9 @@ describe("data masking", () => {

const update = jest.fn();
const onCompleted = jest.fn();
const { takeSnapshot } = renderHookToSnapshotStream(

using _disabledAct = disableActEnvironment();
const { takeSnapshot } = await renderHookToSnapshotStream(
() => useMutation(mutation, { onCompleted, update }),
{
wrapper: ({ children }) => (
Expand All @@ -3097,7 +3091,7 @@ describe("data masking", () => {

const [mutate] = await takeSnapshot();

await act(() => mutate());
await mutate();

expect(onCompleted).toHaveBeenCalledTimes(1);
expect(onCompleted).toHaveBeenCalledWith(
Expand Down

0 comments on commit 624b354

Please sign in to comment.