因果报应并没有执行测试用例

karma is not executing test case

本文关键字:测试用例 执行 并没有 因果报应      更新时间:2023-09-26

我是因果报应的新手。我无法执行测试用例。我有以下设置。

      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.

我可以在浏览器中看到我的第一个Test.js加载。我真的不知道我的代码出了什么问题。我指的是"ProAngularJS"这本书。请让我知道我做错了什么。

编辑

我在浏览器控制台中也遇到了一些错误。

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

"Karma start"似乎只是启动服务器,而不是运行测试。试着在一个控制台中运行"因果报应启动",在另一个控制台运行"因果报应运行"来实际执行测试。您应该在两个控制台窗口中看到与测试执行相关的输出。

或者,您可以编辑karma.conf.js文件以包含"singleRun":true。然后,当您使用karma start时,它将在一个操作中启动浏览器、运行测试和关闭浏览器。