You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I followed the integration tests example pattern in my own app.
// mock the datasources' underlying fetch methods, whether that's a REST
// lookup in the RESTDataSource or the store query in the Sequelize datasource
launchAPI.get = jest.fn(() => [mockLaunchResponse]);
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 no launchAPI.get however there is a launchAPI.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:
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 instanceconst{ server, APIDataSource }=constructTestServer();// mock the datasources' underlying fetch methodsAPIDataSource.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 ApolloServerconst{ query }=createTestClient(server);constres=awaitquery({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.
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: