0
コントローラが未定義のため、私のangularjsテストはすべて失敗しています。私はいくつかの異なるソリューションを試しましたが、何も問題はありません。私はカルマで必要と思ったすべてのjsファイルを追加しました。その外観から、私はbeforeEach(inject ...関数が呼び出されていると思っていません。道に沿っては何も今までbeforeEach(注入...関数呼び出しをカルマ/ジャスミンテストが失敗しました:TypeError:MysmartdevicesCtrlが定義されていません
エラー・ログに印刷されません取得します。
Firefox 49.0.0 (Ubuntu 0.0.0) Controller: RegisteruserCtrl should attach a list of awesomeThings to the scope FAILED
minErr/<@bower_components/angular/angular.js:68:12
loadModules/<@bower_components/angular/angular.js:4640:15
[email protected]_components/angular/angular.js:321:11
[email protected]_components/angular/angular.js:4601:5
[email protected]_components/angular/angular.js:4523:19
[email protected]_components/angular-mocks/angular-mocks.js:3074:44
[3]</ContextKarma/[email protected]://localhost:9876/context.js:151:7
TypeError: RegisteruserCtrl is undefined in test/spec/controllers/registeruser.js (line 21)
@test/spec/controllers/registeruser.js:21:5
[3]</ContextKarma/[email protected]://localhost:9876/context.js:151:7
Firefox 49.0.0 (Ubuntu 0.0.0): Executed 3 of 3 (3 FAILED) ERROR (0.17 secs/0.09 secs)
registerCtrl.js仕様:
'use strict';
describe('Controller: RegisteruserCtrl', function() {
// load the controller's module
beforeEach(module('clientApp'));
var RegisteruserCtrl,
scope;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
RegisteruserCtrl = $controller('RegisteruserCtrl', {
$scope: scope
// place here mocked dependencies
});
}));
it('should attach a list of awesomeThings to the scope', function() {
expect(RegisteruserCtrl.awesomeThings.length).toBe(3);
});
});
karma.conf.js
(/ **/*)minimatchパターンを使用して10// Karma configuration
// Generated on Tue Oct 11 2016 18:25:32 GMT-0500 (CDT)
"use strict";
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '../',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files/patterns to load in the browser
files: [
'bower_components/angular/angular.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-mocks/angular-mocks.js',
'app/**/app.js',
'app/Common/*.js',
'app/scripts/controllers/*.js',
'test/**/*.js'
],
// list of files to exclude
exclude: [],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {},
plugins: [
'karma-firefox-launcher',
'karma-chrome-launcher',
'karma-jasmine',
],
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable/disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable/disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
});
};