角度单元测试:HTML5模式下的$ location需要存在标记

时间:2016-09-06 14:34:50

标签: angularjs unit-testing angular-ui-router html5mode

我正在使用Karma编写我的测试脚本,这是我的karma.conf.js代码



'use strict';

/**
 * Module dependencies.
 */
var _ = require('lodash'),
    karmaReporters = ['spec', 'coverage'];

//Karma configuration
module.exports = function (karmaConfig) {
  karmaConfig.set({

    preprocessors: {
      './index.html': ['ng-html2js'],
      './app/*/modules/*/views/**/*.html': ['ng-html2js'],
      './app/config.js': ['coverage'],
      './app/application.js': ['coverage'],
      './app/*/modules/*/client/*.js': ['coverage'],
      './app/*/modules/*/client/config/*.js': ['coverage'],
      './app/*/modules/*/client/controllers/*.js': ['coverage'],
      './app/*/modules/*/client/directives/*.js': ['coverage'],
      './app/*/modules/*/client/services/*.js': ['coverage']
    },

    ngHtml2JsPreprocessor: {
      moduleName: 'myApp',

      cacheIdFromPath: function (filepath) {
        return filepath;
      }
    },

    // List of files / patterns to load in the browser
    files: [
      './public/libs/angular/angular.js',
      './public/libs/angular-mocks/angular-mocks.js',
      './public/libs/angular-animate/angular-animate.js',
      './public/libs/angular-cookies/angular-cookies.js',
      './public/libs/angular-resource/angular-resource.js',
      './public/libs/angular-route/angular-route.js',
      './public/libs/angular-sanitize/angular-sanitize.js',
      './public/libs/angular-ui-router/release/angular-ui-router.js',
      './public/constants/constants.js',

      './app/config.js',
      './app/application.js',
      './app/*/modules/*/client/*.js',
      './app/*/modules/*/client/**/*.js',
      './app/*/modules/*/tests/unit/*.js',
      './index.html',
      './app/*/modules/*/client/views/**/*.html'
    ],
    basePath: './',
    //frameworks to use
    frameworks: ['jasmine'],

    // Test results reporter to use
    // Possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    reporters: karmaReporters,

    // Configure the coverage reporter
    coverageReporter: {
      dir: './coverage/client',
      reporters: [
        // Reporters not supporting the `file` property
        {type: 'html', subdir: 'report-html'},
        {type: 'lcov', subdir: 'report-lcov'},
        // Output coverage to console
        {type: 'text'}
      ],
      instrumenterOptions: {
        istanbul: {noCompact: true}
      }
    },

    // Level of logging
    // Possible values: karmaConfig.LOG_DISABLE || karmaConfig.LOG_ERROR || karmaConfig.LOG_WARN ||
    // karmaConfig.LOG_INFO || karmaConfig.LOG_DEBUG
    logLevel: karmaConfig.LOG_INFO,

    browsers: ['Chrome'],
    autoWatch: true,
    singleRun: true,
    colors: true
  });
};




据我所知,它在一段时间内工作正常,由于一些变化,我突然得到这个错误,我无法弄清楚可能是什么问题。

Uncaught Error: [$location:no/path/to/my/app] $location in HTML5 mode requires a </path/to/my/app> tag to be present!

我的索引文件中定义了基本网址,但在运行测试脚本时仍然出现此错误

0 个答案:

没有答案