在JavaScript量角器端到端测试中模拟HTTP后端
Mocking the HTTP backend in JavaScript protractor end to end testing
我有一些端到端测试(JavaScript+Protractor),我需要模拟API后端。
我正在使用http后端代理:
我就是这么做的:
var HttpBackend = require('http-backend-proxy');
var myData = require('myFakeApiResponse.json');
this.proxy = new HttpBackend(browser);
this.proxy.whenGET(/.+'/api'/groups'/.+/).respond(200, myData);
JavaScript抱怨whenGET不是一个函数。
如果我喜欢这个:
this.proxy.whenGET(/.+'/api'/groups'/.+/);
它不再抱怨了(但显然我需要设置响应,所以我需要.respond()
部分)
我不明白为什么它不起作用。代理对象似乎已设置,当我控制台日志时,我得到:
{ when: [Function],
whenGET: [Function],
whenPUT: [Function],
whenHEAD: [Function],
whenPOST: [Function],
whenDELETE: [Function],
whenPATCH: [Function],
whenJSONP: [Function],
context: {},
flush: [Function],
syncContext: [Function],
onLoad: [Getter] }
它似乎是一个合适的JavaScript对象(甚至列出了whenGET()函数!)
我也在使用http后端代理。
我需要这个来进行传递(主要是html页面,因为它是一个Angular应用程序):
proxy.onLoad.whenGET(/.*/).passThrough();
以及onLoad:
proxy.onLoad.whenGET('the url').respond(...);
当我使用browser.get(…)进行导航时,会调用onLoad.whenGET。
相关文章:
- 在VanillaJS中模拟模型双向数据绑定
- Meteor如何接收HTTP请求
- 使用jasmine模拟对服务器的调用
- 模拟谷歌地图中的点击
- 在我的情况下,如何进行http请求
- //而不是在src=“”上使用http://"属性
- 使用模拟按键在输入框中自动输入文本
- 模拟chrome.storage.local函数使用Jasmine
- 我无法使用angularJs($http)访问服务器
- 模拟非 HTTP URL 的 .click()
- Ember CLI with http-mock and pretender, 如何管理模拟数据
- Angularjs模拟一个返回$http承诺的函数
- 在JavaScript量角器端到端测试中模拟HTTP后端
- 在测试我的AngularJS控制器时,我如何模拟$http.get承诺中的结果
- 使用模拟HTTP与Protractor和Jasmine
- 全局BeforeEach,用于用Mocha和Angular模拟HTTP请求
- 如何模拟http.ServerResponse和http.express.static的IncomingMessage
- 浏览器化Angular2 HTTP模拟测试
- 为什么要在单元测试中模拟HTTP请求?
- AngularJS:如何正确模拟从$http返回的承诺