在文件dashboard.module.coffee
我有以下聲明:因果報應找不到angularjs指令在它自己的文件
angular
.module('app.dashboard', [])
在另一個文件中,stat.directive.coffee
我有以下幾點:
angular.module('app.dashboard')
.directive('stat', ['$interval', statDirective])
statDirective
包含指令邏輯。此代碼工作正常在瀏覽器中,即<stat>
元素按預期工作,但下面的茉莉花測試不渲染元素,它只是一個空字符串:
describe "Stat", ->
element = null
scope = null
beforeEach module 'app.dashboard'
beforeEach module 'views/templates/dashboard/stat.html'
beforeEach inject ($compile, $rootScope) ->
scope = $rootScope.$new()
element = $compile('<stat></stat>') scope
it "contains some html", ->
scope.$digest()
expect(element.html()).toEqual('<div>hi</div>')
我已經縮小下來的模塊是與指令分開申報。相反,如果該聲明是這樣,該指令被發現,呈現:
angular.module('app.dashboard', [])
.directive('stat', ['$interval', statDirective])
在這裏,唯一的變化是,模塊和指令被宣告在一起,而不是兩個文件。
由於代碼在瀏覽器中工作得很好,這看起來與Karma特別相關。有沒有在我的Karma配置中缺少這種類型的文件結構的工作?
這裏是我的噶配置:
// Karma configuration
// Generated on Mon Jun 29 2015 22:33:24 GMT-0700 (PDT)
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: [
'client/bower_components/jquery/dist/jquery.min.js',
{pattern: 'client/bower_components/**/*.map', watched: false, included: false, served: true},
'client/bower_components/angular/angular.min.js',
'client/bower_components/angular-websocket/angular-websocket.js',
'node_modules/angular-mocks/angular-mocks.js',
'client/views/**/*.html',
'client/scripts/*.module.js',
'client/scripts/**/*.module.js',
'client/scripts/**/*.module.coffee',
'client/scripts/**/*.directive.coffee',
'client/scripts/**/*.controller.coffee',
'client/scripts/**/*.coffee',
'spec/**/*Spec.coffee'
],
// 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: {
'**/*.coffee': ['coffee'],
'client/views/**/*.html': 'ng-html2js'
},
ngHtml2JsPreprocessor: {
// strip app from the file path
stripPrefix: 'client/'
},
// 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: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
})
};
謝謝!
發表您的karma.config文件YOH 。 – SoEzPz
@SoEzPz編輯了包含karma配置的問題,謝謝! – berto