首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AngularJS模块.run顺序和e2e模拟

AngularJS模块.run顺序和e2e模拟
EN

Stack Overflow用户
提问于 2013-05-09 07:14:55
回答 1查看 514关注 0票数 2

我正在为AngularJS做一些E2E测试。

我已经实现了一个$httpBackend ngMockE2E。

这很有效,但是在某些情况下,HTTP请求是在我的mock完全设置之前发出的。

模拟设置为:

代码语言:javascript
复制
  angular.module('Mock', ['ngMockE2E']).

    run(function($httpBackend) {

      $httpBackend.whenPOST('/path1').respond({ exampleresponse: 'valid' });
      $httpBackend.whenPOST('/path2').respond({ exampleresponse: 'valid' });

它的用法如下:

代码语言:javascript
复制
angular.module('Application', ['FirstDependency', 'Mock', 'ThirdDependency']);

但是,FirstDependency和ThirdDependency可以发出HTTP请求,这有时发生在模拟.run()块执行之前。这会导致请求错误。

我的mock设置正确吗?确保我的mock以正确的顺序加载的最好方法是什么?

EN

回答 1

Stack Overflow用户

发布于 2013-09-25 19:50:47

医生是这么说的:

代码语言:javascript
复制
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/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16451767

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档