业力不执行testing用例
我是业力新手。 我无法执行testing用例。 我有以下设置。
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
“Karma start”似乎只是启动服务器,不能运行testing。 尝试在一个控制台中运行“业力开始”,在另一个控制台中运行“业力运行”来实际执行testing。 您应该在与testing执行相关的控制台窗口中看到输出。
或者,您可以编辑karma.conf.js文件以包含“singleRun”:true。 那么当你使用karma start的时候,它会启动浏览器,运行testing,然后closures浏览器。