apollographql / apollographql/fullstack-tutorial
Integration Tests Not Properly Mocked
- Langage dominant
- TypeScript
- Étoiles
- 1.2k
- Forks
- 808
- Métriques de merge des PR
- Aucune PR mergée en 30 j
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?
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par exécuter les tests d’intégration avec le réseau désactivé et examinez l’exemple qui assigne launchAPI.get, puis suivez la méthode de RESTDataSource qui gère la recherche du lancement. L’issue ne nomme aucun fichier ni aucune commande de test ; le travail est terminé lorsque les tests d’intégration passent hors ligne sans demander api.spacexdata.com et renvoient toujours les données attendues de la fusée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- graphql, node.js, typescript
- Domaine
- api, backend, testing
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 35/100