Testing service in Angular returns module is not defined

后端 未结 7 1177
借酒劲吻你
借酒劲吻你 2020-12-13 03:11

I am trying to run the default service unit test in my project (Taken from the Angular Seed project on GitHub), but I keep getting the error \"module is not defined\".

7条回答
  •  天涯浪人
    2020-12-13 03:45

    The window.module function comes in angular-mocks.js and is a shorthand for angular.mock.module. As mentioned in the docs, the module function only works with Jasmine.

    Using Testacular, the following example configuration file will load angular-mocks.js.

    /** example testacular.conf.js */
    
    basePath = '../';
    files = [
      JASMINE,
      JASMINE_ADAPTER,
      'path/to/angular.js',
      'path/to/angular-mocks.js',   // for angular.mock.module and inject.
      'src/js/**/*.js',             // application sources
      'test/unit/**/*.spec.js'      // specs
    ];
    autoWatch = true;
    browsers = ['Chrome'];
    

    And, as suggested elsewhere, you can run Testacular with debug logging to see what scripts are loaded (you can also see the same in the inspector):

    testacular --log-level debug start config/testacular.conf.js
    

    The angular.mock.inject docs include a pretty complete example.

提交回复
热议问题