-
Notifications
You must be signed in to change notification settings - Fork 121
Open
Labels
Description
Hey
Im trying to Mock an API request following the Apollo docs for MockProvider, for some reason jest dom is returning a "?", nothing inside my mockQuery is firing it seems, even the error is not being displayed. Any console logs also don't get rendered.
Does MockProvider even work with rest link? Any help would be much appreciated. Some example code below if it helps
export const currentUserFragment: DocumentNode = gql`
fragment UserFields on User {
avatar: _avatar
name
}
`;
const queryMocks = [
{
error: new Error("something went wrong"),
request: {
query: query(currentUserFragment),
variables: {
id: "1",
},
},
result: {
data: {
user: {
avatar: {
url: "image.jpg",
},
id: "1",
name: "Jay Youngman",
},
},
},
},
];
const renderWithContext = (
overrideContextValue: Partial<GlobalContextValue> = {},
overrideProps: Partial<HeaderProps> = {}
) =>
render(
<GlobalContext.Provider
value={{ ...globalContextMockValue, ...overrideContextValue }}
>
<MockedProvider addTypename={false} mocks={queryMocks}>
<Header {...defaultProps} {...overrideProps} />
</MockedProvider>
</GlobalContext.Provider>
);
it("displays the users name", async () => {
renderWithContext();
await wait(0);
const userName = screen.getByText("Jay Youngman");
screen.debug();
expect(userName).toBeInTheDocument();
});
Query
gql`
query UseCurrentUserQuery($id: ID) {
user(id: $id) @rest(path: "/users/{args.id}", type: "User") {
...UserFields
id
}
}
${fragment}
`;
Thanks
/label Question