AngularJS 量角器 E2E 模拟 [英] AngularJS Protractor E2E Mocking

查看:21
本文介绍了AngularJS 量角器 E2E 模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Angular SPA 从节点后端检索其数据.由于节点项目完全被测试覆盖,我想模拟 Angular HTTP 调用.(我不想开始讨论一般的功能/烟雾测试,谢谢).

I have an Angular SPA retrieving its data from a node backend. Since the node project is fully covered with tests I want to mock the Angular HTTP calls. (I do not want to start a discussion about functional-/smoke-tests in general, thanks).

我想要的是s.th.像这样

What I'd like to have is s.th. like this

Api = $injector.get('Api');
sinon.mock(Api, 'getSomethingFromServer').andRespondWith({foo: 'bar'})
assert(Api.getSomethingFromServer.wasCalledOnce);

但无论如何我都找不到好的解决方案.我发现了几个关于同一问题的帖子.对于例如这个.

But no matter how I can't find a nice solution. I found several posts regarding the same issue. For example this one.

由于量角器变化很大且频繁,所以我只想在这里询问是否有人找到了模拟 HTTP 请求的合适解决方案.

Since protractor is changing a lot and frequently, I just like to ask here on SO if anyone found a proper solution for mocking the HTTP requests.

推荐答案

我同意之前的回答.对于 Protractor 频繁更改的解决方案是将后端与被测系统完全去相关,无论它是模拟、存根还是假的.

I agree with previous answer. An answer to frequent change of Protractor is to completly decorrelate the backend from the system under test, no matter if it is mock, stub, or fake.

困难在于保持与真实后端的强一致性,但并不是说这比试图保持一种不断变化的 angular 模拟方式的开销更大.

The difficulty is to maintain a strong coherence with the real backend, but it is not said that it is more overhead than trying to maintain an always changing way of mocking with angular.

这篇关于AngularJS 量角器 E2E 模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆