angularjs、因果报应和requirejs测试用例错误
angularjs, karma and requirejs test case error
我的angularjs应用程序使用requirejs卡。根据这篇文章,我正在编写我的测试用例,但在执行测试用例时总是会出现这个错误
Error: [$injector:modulerr] Failed to instantiate module sampleapp due to:
Error: [$injector:nomod] Module 'sampleapp' 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.
测试用例:
define([
'angular',
'angular-mocks'
], function() {
describe('main controller todo app', function() {
var scope, ctrl;
beforeEach(module('sampleapp',[]));
beforeEach(inject(function($rootScope, $controller) {
scope = $rootScope.$new();
ctrl = $controller('mainCtrl', {$scope: scope});
}));
it('is todo added', function() {
scope.todo = 'My new Todo';
scope.addTodo();
assert.equal(scope.todos.length, 1);
});
})
});
因果报应:
module.exports = function(config) {
'use strict';
config.set({
basePath: './',
frameworks: [
'requirejs',
'mocha',
'chai'
],
files: [{
pattern: 'test/test-main.js',
watched: true
}, {
pattern: 'app/angular/**/*.js',
included: false
}, {
pattern: 'app/*.js',
included: false
}, {
pattern: 'app/scripts/additional/**/*.js',
included: false
}, {
pattern: 'test/spec/**/*.js',
included: false,
watched: true
}],
exclude: [
'app/main.js'
],
reporters: ['spec'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
captureTimeout: 20000,
singleRun: false,
plugins: [
'karma-chai',
'karma-mocha',
'karma-requirejs',
'karma-spec-reporter',
'karma-chrome-launcher'
]
});
}
主测试:
var tests = [];
var TEST_REGEXP = /test[A-Za-z0-9]{1,}-[A-Za-z0-9]{1,}'.js/i;
Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
tests.push(file);
}
});
requirejs.config({
'baseUrl': '/base/app',
'paths': {
'angular': 'scripts/additional/angular/angular',
'angular-mocks': 'scripts/additional/angular-mocks/angular-mocks',
},
'shim': {
'angular-mocks' : {'exports' : 'angular-mocks', 'deps': ['angular']}
},
'deps': tests,
'callback': window.__karma__.start
});
非常感谢任何帮助或指导来解决此问题
主要问题是没有加载创建模块的文件(即执行代码var app = angular.module("sampleapp",[]);
的文件)
一旦纠正了这一点,一切都开始工作
相关文章:
- angularjs、因果报应和requirejs测试用例错误
- 我们能在&在块到mocha的特定测试用例(it)之后
- 在Karma Jasmine单元测试用例中检查日期格式
- 正在量角器测试用例中从电子邮件中获取值
- 如何将 XML 文件包含在摩卡测试用例中
- 如何将行数计数分配给另一个值,该值稍后可在Protractor中的测试用例中使用
- 如何在启动Mocha测试用例之前添加延迟
- 如何在nightwach中检索当前测试用例名称
- 如何在多个文件中设置摩卡测试用例的执行顺序
- 如何在断言失败时继续测试用例 在 CasperJS 中
- 为什么在我的量角器测试用例中没有定义网络驱动程序
- 猫鼬模型单元测试 - 如果任何测试用例失败,连接将不会关闭
- 如何在量角器 e2e 测试用例失败时发送电子邮件
- 测试用例在 Chrome 中失败
- 如何在摩卡的测试用例中调用另一个测试用例
- 如何处理单元测试用例的q和promise
- ECMAScript 5日期.ISO 8601测试用例的分析结果
- 如何在运行JEST测试用例时将全局变量设置为true
- 如何在jasmine测试用例中模拟$(element).show和ko.mapping.fromJS
- 茉莉测试用例错误'间谍被调用'