Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Integration Tests Not Properly Mocked

Open
#90 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
graphql, node.js, typescript
Domain
api, backend, testing

Research direction

Start by running the integration tests with networking disabled and inspect the example that assigns launchAPI.get, then trace which RESTDataSource method handles the launch lookup. The issue names no files or test command; done should mean the integration tests pass offline without requesting api.spacexdata.com and still return the expected rocket data.

Written by the indexing model from the issue text.

Description

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.

errors": Array [
    +     Object {
    +       "extensions": Object {
    +         "code": "INTERNAL_SERVER_ERROR",
    +         "exception": Object {
    +           "code": "ENOTFOUND",
    +           "errno": "ENOTFOUND",
    +           "message": "request to https://api.spacexdata.com/v2/launches?flight_number=30 failed, reason: getaddrinfo ENOTFOUND api.spacexdata.com api.spacexdata.com:443",
    +           "type": "system",
    +         },
            },
    -       "rocket": Object {
    -         "type": "FT",
    -       },
    +       "locations": Array [
    +         Object {
    +           "column": 3,
    +           "line": 2,
    +         },
    +       ],
    +       "message": "request to https://api.spacexdata.com/v2/launches?flight_number=30 failed, reason: getaddrinfo ENOTFOUND api.spacexdata.com api.spacexdata.com:443",
    +       "path": Array [
    +         "launch",
    +       ],

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?

Dominant language
TypeScript
Stars
1.2k
Forks
808
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apollographql/fullstack-tutorial

All issues in apollographql/fullstack-tutorial

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.