-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration Tests Not Properly Mocked #90
Comments
Ok I was able to properly mock it by doing this. describe("Queries", () => {
it("fetches an author stream header", async () => {
// create an instance of ApolloServer, while reusing
// existing dataSources, resolvers, and typeDefs.
// This function returns the server instance as well as our dataSource
// instances, so we can overwrite the underlying fetchers
// APIDataSource is an uninvoked class instance
const { server, APIDataSource } = constructTestServer();
// mock the datasources' underlying fetch methods
APIDataSource.prototype.get = jest.fn(() => mockServerAuthorResponse);
// use our test server as input to the createTestClient fn
// This will give us an interface, similar to apolloClient.query
// to run queries against our instance of ApolloServer
const { query } = createTestClient(server);
const res = await query({
query: GET_AUTHOR,
variables: { username: "amy87" },
});
expect(res).toMatchSnapshot();
});
}); |
Why not use something like https://github.com/aexmachina/factory-girl ? mocking calls to the database for an integration tests or even testing the resolvers seems like a red flag. What if the queries in the UserAPI aren't right? And then if the User model is changed you have to change the mock everywhere. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I followed the integration tests example pattern in my own app.
However I noticed it was still making api calls to the rest endpoint. I then cloned this repo turned off my wifi and ran the integration tests and sure enough I got an error.
This tells me that
launchAPI.get
is not being properly mocked. Which I think would make sense as there is nolaunchAPI.get
however there is alaunchAPI.prototype.get
however that doesn't seem to work when I change the tests to that.Any ideas?
The text was updated successfully, but these errors were encountered: