I am using graphql-tag and supertest-graphql to test my apollo-server-express app.
The following is my current approach.
it('Query a quote', async () => {
const id = '123456';
const res = await request(app)
.query(
gql`
query ($id: String!) {
word(id: $id) {
id
}
words {
id
}
}
`
)
.variables({ id: id });
console.log(res.data);
expect((res.data as any).word.id).toBe('123456');
});
In the client side, I am using graphql-request. This is why I want to use graphql-request's request instead of supertest-graphql's request in my unit tests.
However, I cannot find any solution to do this job. Anyone has any idea?
At the end, I started an actual express server to run my test.
something like this:
If anyone has a better idea, I am eager to learn.