如何嘲笑后端的第三方API调用
我正在用摩卡和超级testing我的应用程序,所以我的testing总是像
var request = require('supertest'), app = require('./bootstrap.js'); describe('...', function() { it('...', function() { request(app) .get('/some/url') // ... });
});
在监听端口之前,bootstrap.js是我真正的应用程序
所有的作品都很完美,但是最近我不得不添加对第三方API的调用,而且testing速度很慢
所以当我这样做,例如testing需要5秒钟
request(app) .get('/my/endpoint/that/makes/call/others') // ...
如何在testing过程中做出虚假的电话,但在运行我的应用程序时是否真实?
你可以使用nock来达到这个目的。
- 如果在抛出任何错误的时候如何在promise中做出断言,不会冒出来呢?
- Sinon – 如何存根嵌套函数?
- 摩卡APItesting:得到'TypeError:app.address不是一个函数'
- 断言在摩卡testing中打破asynchronousfunction
- 期望断言types错误 – >期望(…).toExist不是一个函数
- 我怎么能得到伊斯坦布尔与节点,摩卡,茉莉花和js要求
- 你如何安装和运行Mocha,Node.jstesting模块? 安装后得到“mocha:command not found”
- 使用摩卡进行unit testing的电解质依赖性注入
- 当用Chai进行unit testing时,“TypeError:无法读取属性”的“undefined”地址是什么意思?