apollographql / apollographql/fullstack-tutorial

Integration Tests Not Properly Mocked

未关闭
#90 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
1.2k
派生
808
PR 合并指标
30 天内没有已合并 PR

描述

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?

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先在禁用网络的情况下运行集成测试,并检查为 launchAPI.get 赋值的示例,然后追踪负责处理发射查询的 RESTDataSource 方法。issue 未指定文件或测试命令;完成的标准是集成测试能够离线通过,不请求 api.spacexdata.com,并且仍然返回预期的火箭数据。

由索引模型根据 Issue 内容生成。

评估

技术栈
graphql, node.js, typescript
领域
api, backend, testing
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。