我正在为AngularJS做一些E2E测试。
我已经实现了一个$httpBackend ngMockE2E。
这很有效,但是在某些情况下,HTTP请求是在我的mock完全设置之前发出的。
模拟设置为:
angular.module('Mock', ['ngMockE2E']).
run(function($httpBackend) {
$httpBackend.whenPOST('/path1').respond({ exampleresponse: 'valid' });
$httpBackend.whenPOST('/path2').respond({ exampleresponse: 'valid' });它的用法如下:
angular.module('Application', ['FirstDependency', 'Mock', 'ThirdDependency']);但是,FirstDependency和ThirdDependency可以发出HTTP请求,这有时发生在模拟.run()块执行之前。这会导致请求错误。
我的mock设置正确吗?确保我的mock以正确的顺序加载的最好方法是什么?
发布于 2013-09-25 19:50:47
医生是这么说的:
Dependencies:
Modules can list other modules as their dependencies.
Depending on a module implies that required module needs to be loaded
before the requiring module is loaded. In other words the
configuration blocks of the required modules execute before the
configuration blocks of the requiring module. The same is true for the
run blocks. Each module can only be loaded once, even if multiple
other modules require it.然而,它没有说明的是,它将首先执行,然后执行所有模块的配置块(依赖项优先),然后执行,然后执行,它将依次为每个模块执行一行中的所有其他块。有关这一点的说明,请看下面的jsfiddle:
http://jsfiddle.net/9FJnZ/2/
https://stackoverflow.com/questions/16451767
复制相似问题