Gulp测试找不到模块

寄件人

我使用gulp angular生成了Web应用程序然后,我创建了一个服务,并希望对其进行测试。

模块文件是app.module.js

angular.module('text', []);

服务文件是text.service.js

(function () {
  'use strict';
  angular.module('text')
    .factory('description',TextService);

  TextService.$inject = ['$http']

  function TextService($http) {

    return {
      QueryStaticText: queryStaticText

  };

    function queryStaticText(link) {
      return link;
    }
  }

})();

测试文件为text.service.spec.js

'use strict';

describe('TextService', function () {
  var description;

  beforeEach(function () {

    module('text');

    inject(function (_description_) {
      description = _description_;
    });

  });

  it('should return text', function () {
    expect(description.QueryStaticText("Hello")).toEqual("Hello anu");
  });
});

在控制台中,我执行了gulp测试,并且收到了错误消息

[22:02:44] Using gulpfile /Volumes/Developer/angularjs/project/gulpfile.js
[22:02:44] Starting 'test'...
[22:02:45] Starting Karma server...
INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Mac OS X)]: Connected on socket 1KW_uYCk45moVKwfgAd2 with id 19804685
PhantomJS 1.9.8 (Mac OS X) ERROR
  Error: [$injector:nomod] Module 'text' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
  http://errors.angularjs.org/1.3.12/$injector/nomod?p0=text
  at /Volumes/Developer/angularjs/project/bower_components/angular/angular.js:1769



/Volumes/Developer/angularjs/project/gulp/unit-tests.js:30
      throw err;

文本模块未加载,如何加载?

英美

看来您没有按顺序在Karma中加载文件。在您的karma.conf.js内部,应该有一个文件列表。加载应用程序模块,然后加载其余的javascript。这是一个有同样问题的帖子

例如:

files: [
  'bower_components/angular/angular.js',
  'bower_components/angular-mocks/angular-mocks.js',
  'bower_components/angular-animate/angular-animate.js',

  'app/**/*.module.js',  // Loads all files with .module.js
  'app/**/*.js',         // Load the rest of your .js angular files
  'test/**/*.js'         // Load your tests
],

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Gulp错误(找不到模块)

来自分类Dev

Gulp和Babel:错误:找不到模块

来自分类Dev

因果未运行-找不到模块gulp

来自分类Dev

Gulp错误:找不到模块browserify

来自分类Dev

找不到gulp-plumber模块?

来自分类Dev

Gulp和Babel:错误:找不到模块

来自分类Dev

找不到模块“gulp-gitinfo”

来自分类Dev

`npm run gulp`找不到模块'gulp-shell'吗?

来自分类Dev

Gulp错误:找不到模块'gulp-watch'

来自分类Dev

Gulp错误:找不到模块'gulp-watch'

来自分类Dev

角茉莉测试找不到模块

来自分类Dev

在Anaconda Python中找不到测试模块

来自分类Dev

找不到鼻子测试 Web 模块

来自分类Dev

在 AVA 测试中找不到模块

来自分类Dev

Gulp与browserify:找不到模块src / js / main.js

来自分类Dev

Gulp-throw err找不到模块'q'

来自分类Dev

发布到Azure时找不到模块gulp.js

来自分类Dev

Gulp需要“找不到模块”,即使它存在

来自分类Dev

Typescript + Gulp + Protractor =>找不到模块config.js

来自分类Dev

Gulp运行业力测试-找不到变量:角度

来自分类Dev

Gulp运行业力测试-找不到变量:角度

来自分类Dev

AngularJS单元测试中找不到模块错误

来自分类Dev

错误:使用Mocha测试时找不到模块

来自分类Dev

karma-browserify在单元测试中找不到模块

来自分类Dev

运行测试时,virtualenv找不到安装的模块[Pytest]

来自分类Dev

使用JEST运行Angular组件测试给出找不到模块

来自分类Dev

设置角度控制器测试时找不到模块

来自分类Dev

运行测试时,virtualenv找不到安装的模块[Pytest]

来自分类Dev

业力测试,PhantomJS错误:找不到模块“事件”