$injector:诺莫德与业力+茉莉花



我正在努力用Karma和Jasmine运行基本的UT。看起来 Karma/Jasmine 在运行测试时无法拾取模块。运行npm start时,我没有收到相同的错误。

我收到以下错误:

Chrome 69.0.3497 (Windows 10 0.0.0) ERROR
{
"message": "An error was thrown in afterAllnUncaught Error: [$injector:nomod] Module 'UTAppV2' 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.nhttps://errors.angularjs.org/1.7.4/$injector/nomod?p0=UTAppV2",
"str": "An error was thrown in afterAllnUncaught Error: [$injector:nomod] Module 'UTAppV2' 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.nhttps://errors.angularjs.org/1.7.4/$injector/nomod?p0=UTAppV2"
}
Chrome 69.0.3497 (Windows 10 0.0.0): Executed 1 of 1 ERROR (0.01 secs / 0.001 secs)
npm ERR! Test failed.  See above for more details.

我的业力.js文件

module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',
'app/*.spec.js',
'app/*.component.js',
'app/*.module.js',
'app.js'
],
exclude: [],
preprocessors: {},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: true,
concurrency: Infinity,
})
}

包.json 文件

{
"name": "uttestingv2",
"version": "1.0.0",
"description": "UT Testing V2",
"main": "index.js",
"scripts": {
"test": "karma start karma.conf.js",
"start": "http-server -a localhost -p 8000 -c-1"
},
"author": "Luke",
"license": "ISC",
"dependencies": {
"angular": "^1.7.4",
"angular-mocks": "^1.7.4",
"jasmine": "^3.2.0",
"karma": "^3.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-jasmine": "^1.1.2"
}
}

Test.spec.js 文件

describe('Basic Test', function () {
beforeEach(module('UTAppV2'));
it('has a dummy spec to test', function () {
expect(4).toBe(4);
});
});

应用.js

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

索引.html

<!doctype html>
<html ng-app="UTAppV2">
<head>
<script src = "node_modules/angular/angular.js"></script>
<script src="app.js"></script>
</head>
<body>
<div>
<p>Nothing here {{'yet' + '!'}}</p>
</div>
</body>
</html>

运行测试时如何解决以下错误:

模块"UTAppV2"不可用!

可能是内存中未清除的对象的组合,以及在 Karma 配置文件中的组件之后定义的模块的组合。

最新更新