首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用ng-html2js进行AngularJS组件测试

用ng-html2js进行AngularJS组件测试
EN

Stack Overflow用户
提问于 2017-04-20 08:05:48
回答 1查看 231关注 0票数 0

有人能帮我解决这个问题吗?

角项目:

gui_service/client/src/js/remoteGuiApp.js:

代码语言:javascript
复制
angular.module('remoteGuiApp', ['ui.bootstrap', 'ngRoute', 'ngSanitize', 'ngResource'])

gui_service/client/src/modules/login/login.js

代码语言:javascript
复制
angular.module('remoteGuiApp')
.component('login', {
    controller: function () {
        this.login = '';
        this.password = '';
        this.showError = false;
    },
    templateUrl: '/src/modules/login/login.html'
});

此外,我还有这个组件的'/src/modules/login/login.html‘模板。

gui_service/client/test/karma.conf

代码语言:javascript
复制
module.exports = function (config) {
    'use strict';
    config.set({

        basePath: '',

        frameworks: ['mocha', 'chai'],

        files: [
            '../src/vendor/js/angular.min.js',
            '../src/vendor/js/angular-mocks.js',
            '../src/vendor/js/angular-route.min.js',
            '../src/vendor/js/angular-resource.min.js',
            '../src/vendor/js/angular-sanitize.min.js',
            '../src/vendor/js/angular-cookies.min.js',

            //Library Files
             '../src/vendor/js/jquery-2.2.4.min.js',
             '../src/vendor/js/moment.js',
             '../src/vendor/js/bootstrap.min.js',
             '../src/vendor/js/ui-bootstrap.js',

            '../src/js/remoteGuiApp.js',
            '../src/js/Authentication.js',
            '../src/modules/login/login.js',

            //tests
             '*.js',
             //templates
             '../src/modules/**/*.html'
        ],

        // generate js files from html templates
        preprocessors: {
           '../src/modules/**/*.html': ['ng-html2js']
        },

        ngHtml2JsPreprocessor: {
            // strip this from the file path
            stripPrefix: 'client/'
        },

        reporters: ['mocha'],

        port: 9876,
        colors: true,
        autoWatch: true,
        singleRun: false,

        // level of logging
        logLevel: config.LOG_INFO,

        browsers: ['Chrome'],

        concurrency: Infinity
    });
};

最后我的问题是:gui_service/client/test/LoginComponent-test.js:

代码语言:javascript
复制
describe('Component: login', function () {
    beforeEach(module('remoteGuiApp'));

    // load the login template
    beforeEach(module('/src/modules/login/login.html'));

    let scope;
    let element;
    let controller;

    beforeEach(inject(function($rootScope, $compile) {
        element = angular.element('<login></login>');

        scope = $rootScope.$new();
        $compile(element)(scope);
        scope.$digest();
    }));

  it('Controller fields', function(done) {
      expect(true).true;
      done();
  });

});

由于启动业力,我犯了如下错误:角链误差

也许有人会告诉这个问题的解决方案。谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-21 08:38:46

我解决了。主要问题是在道路上。因此,如果您需要配置用于测试角指令/组件的karma.conf.js,请小心使用标记:

代码语言:javascript
复制
basePath: ''
preprocessors: ''
ngHtml2JsPreprocessor: {
            stripPrefix: ''
            prependPrefix: ''
        },

仔细阅读手册https://github.com/karma-runner/karma-ng-html2js-preprocessor/blob/master/README.md#configuration,以免像我那样踩在耙上)

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

https://stackoverflow.com/questions/43513701

复制
相关文章

相似问题

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