gpt4 book ai didi

javascript - 使用 karma 和 jasmine 的 Angularjs 基本测试用例,不起作用

转载 作者:行者123 更新时间:2023-12-03 12:38:21 24 4
gpt4 key购买 nike

我是 Angular Testing 的新手。这里运行 karma 没有错误。Expected(true).toBe(true) 和 Expected(false).toBe(true) 给出与下面相同的输出,我不知道为什么。

karma start test/karma.conf.js
INFO [karma]: Karma v0.12.16 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 34.0.1847 (Mac OS X 10.9.2)]: Connected on socket VDytVxMpXMxN0QTPU_kg with id 83112246
Chrome 34.0.1847 (Mac OS X 10.9.2): Executed 0 of 0 ERROR (0.022 secs / 0 secs)

karma.conf.js

// Karma configuration

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: [
//'app/*/*.js'
'app/bower_components/angular/angular.js',
'app/bower_components/jquery/jquery.js',
'app/bower_components/underscore/underscore-min.js',
'app/bower_components/jquery.cookie/jquery.cookie.js',
'app/bower_components/restangular/dist/restangular.min.js',
'app/bower_components/angular-resource/angular-resource.min.js',
'app/bower_components/angular-route/angular-route.min.js',
'app/bower_components/angular-route-segment/build/angular-route-segment.min.js',
'app/bower_components/angular-cookies/angular-cookies.js',
'app/bower_components/angular-sanitize/angular-sanitize.js',
'app/bower_components/angular-scenario/angular-scenario.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/scripts/lib/ui-bootstrap-custom-0.10.0.min.js',
'app/scripts/lib/jquery-ui-1.10.3.custom.js',
'app/scripts/app.js',
'app/scripts/config/*.js',
'app/scripts/controllers/*.js',
'app/scripts/directives/*.js',
'app/scripts/services/*.js',
'app/scripts/filters/*.js',

'test/spec/controllers/main.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
});
};

测试/规范/ Controller /main.js

'use strict';

describe('Controller: MainCtrl', function () {

it('should attach a list of awesomeThings to the scope', function () {
expect(true).toBe(false);
});
});

最佳答案

将 karma.conf.js 放入应用程序根目录中,然后运行 ​​karma start

从您运行的命令来看,配置文件似乎位于 test 目录中,但您已指定规范文件位于 test/spec/controllers。我猜这是一个错误。

关于javascript - 使用 karma 和 jasmine 的 Angularjs 基本测试用例,不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23630120/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com