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 28, 2024
1 parent cfa57ef commit 31f23fc
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 31f23fc

Please sign in to comment.