我是业力新手。我无法执行测试用例。我有以下设置。
karma.config.js
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: [
'angular.js','angular-mocks.js' ,'tests/firstTest.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: {
},
// 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
});
};
firstTest.js
describe("First Test", function () {
// Arrange (set up a scenario)
var counter;
beforeEach(function () {
counter = 0;
});
it("increments value", function () {
// Act (attempt the operation)
counter++;
// Assert (verify the result)
expect(counter).toEqual(1);
})
it("decrements value", function () {
// Act (attempt the operation)
counter--;
// Assert (verify the result)
expect(counter).toEqual(0);
})
});
我在使用' karma start karma.config.js'命令。
INFO[karma]:karma v0.12.31 server started at http://localhost:9876/
INFO[launcher]:Starting broswer Chrome
INFO[Chrome 41.0.2272 (windows 7)]: connected on socket ...... with id 98...
但在此之后没有任何反应,在Chrome浏览器中它只显示
karma v0.12.31 Connected
chrome 41 (windows 7 ) executing.
我能够在浏览器中看到我的firstTest.js被加载。我真的不知道我的代码有什么问题。我指的是Pro AngularJS'书。请让我知道我在做什么。
修改
我在浏览器控制台中也遇到了一些错误。
Uncaught SyntaxError: Unexpected identifier context.html 28
Uncaught TypeError: Cannot read property 'config' of undefined adapter.js 322
Uncaught TypeError: Cannot read property 'loaded' of undefined context.html
答案 0 :(得分:1)
" Karma开始"似乎只是启动服务器但不运行测试。尝试运行" karma start"在一个控制台中,"业力运行"在另一个控制台中实际执行测试。您应该在两个控制台窗口中看到与测试执行相关的输出。
或者,您可以编辑karma.conf.js文件以包含" singleRun":true。然后当你使用karma start时,它将启动浏览器,运行测试,并在一个动作中关闭浏览器。