【问题标题】:AngularJS module .run order and e2e mocksAngularJS 模块 .run 顺序和 e2e 模拟
【发布时间】:2013-05-03 08:07:00
【问题描述】:

我正在为 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 请求,这有时会在 Mock .run() 块执行之前发生。这会导致请求错误。

我是否正确设置了我的模拟?确保我的模拟以正确的顺序加载的最佳方法是什么?

【问题讨论】:

    标签: angularjs angularjs-module


    【解决方案1】:

    文档是这样说的:

    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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多