Skip to content

Commit

Permalink
Add tests for @unmask
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 27, 2024
1 parent 89f15e8 commit e35c203
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/react/hooks/__tests__/useSubscription.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,96 @@ describe("data masking", () => {

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

test("uses unmasked data when using the @unmask directive", async () => {
const subscription = gql`
subscription NewCommentSubscription {
addedComment {
id
...CommentFields @unmask
}
}
fragment CommentFields on Comment {
comment
author
}
`;

const link = new MockSubscriptionLink();
const client = new ApolloClient({
dataMasking: true,
cache: new Cache(),
link,
});

const onData = jest.fn();
const ProfiledHook = profileHook(() =>
useSubscription(subscription, { onData })
);

render(<ProfiledHook />, {
wrapper: ({ children }) => (
<ApolloProvider client={client}>{children}</ApolloProvider>
),
});

{
const { data, loading, error } = await ProfiledHook.takeSnapshot();

expect(loading).toBe(true);
expect(data).toBeUndefined();
expect(error).toBeUndefined();
}

link.simulateResult({
result: {
data: {
addedComment: {
__typename: "Comment",
id: 1,
comment: "Test comment",
author: "Test User",
},
},
},
});

{
const { data, loading, error } = await ProfiledHook.takeSnapshot();

expect(loading).toBe(false);
expect(data).toEqual({
addedComment: {
__typename: "Comment",
id: 1,
comment: "Test comment",
author: "Test User",
},
});
expect(error).toBeUndefined();

expect(onData).toHaveBeenCalledTimes(1);
expect(onData).toHaveBeenCalledWith({
client: expect.anything(),
data: {
data: {
addedComment: {
__typename: "Comment",
id: 1,
comment: "Test comment",
author: "Test User",
},
},
loading: false,
error: undefined,
variables: undefined,
},
});
}

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

describe.skip("Type Tests", () => {
Expand Down

0 comments on commit e35c203

Please sign in to comment.