【发布时间】:2015-10-19 12:10:33
【问题描述】:
设置 Angular 种子,一切正常,我什至可以启动 jasmine 浏览器,但由于某种原因我的规范不起作用,所以我添加了一个 karma.conf 文件,它似乎破坏了 jasmine 浏览器。我是使用 Jasmine 的新手,所以我很茫然,关于如何最好地做到这一点有很多意见,但无论我尝试什么,我似乎都无法让它工作,我在这里添加了 repo 链接对于代码。希望有人能看到我做错了什么。
这个种子需要 NodeJS
下载git,放到文件夹里 进入文件夹,进入根目录下的config文件夹 运行 npm 安装 然后运行 gulp,它会自动在浏览器中启动 在控制台中你会看到这个错误
[14:52:17] 'jasmineWeb' errored after 2.27 ms
[14:52:17] TypeError: object is not a function
at Gulp.<anonymous> (/webdev/E20/config/gulpfile.js:137:11)
at module.exports (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at /webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:279:18
at finish (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
at module.exports (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:60:3)
at Gulp.Orchestrator._runTask (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at /webdev/E20/config/node_modules/gulp/node_modules/orchestrator/index.js:279:18
这是我用来启动 Jasmine 的任务
gulp.task('jasmineWeb', function() {
var filesForTest = ['../src/**/*.js', '../src/**/*_spec.js']
return gulp.src(filesForTest)
.pipe(karma({configFile: 'karma.conf.js',action: 'run'}))
.pipe(watch(filesForTest))
.pipe(jasmineBrowser.specRunner())
.pipe(jasmineBrowser.server({port: 8888}));
});
这是我的 Karma.conf 文件
// Karma configuration
// Generated on Tue Jul 28 2015 11:28:22 GMT-0400 (EDT)
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: [
'../src/lib/js/angular/angular.min.js',
'../src/lib/js/angular/angular-mocks.js',
'../src/com/**/*.js',
'../src/com/**/*_spec.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', 'Firefox', 'IE', 'PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
})
}
提前表示感谢
https://bitbucket.org/baylysoft/angular-seed-project
Karma 现在正在运行,但我现在收到此错误
PhantomJS 1.9.8 (Mac OS X 0.0.0) Controller: com/modules/AboutController Sets the Page Message It should show the page message FAILED
ReferenceError: Can't find variable: $scope
at /webdev/E20/src/com/modules/about/aboutController_spec.js:15
Chrome 44.0.2403 (Mac OS X 10.10.4) Controller: com/modules/AboutController Sets the Page Message It should show the page message FAILED
ReferenceError: $scope is not defined
at Object.<anonymous> (/webdev/E20/src/com/modules/about/aboutController_spec.js:15:16)
Chrome 44.0.2403 (Mac OS X 10.10.4): Executed 1 of 1 (1 FAILED) ERROR (0.008 secs / 0.006 secs)
PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0 secs / 0.004 secs)
这是更新的规范文件
'use strict';
describe('Controller: com/modules/AboutController', function() {
beforeEach(module(app));
var $controller;
beforeEach(inject(function(_$controller_){
// The injector unwraps the underscores (_) from around the parameter names when matching
$controller = _$controller_;
}));
describe('Sets the Page Message', function() {
it('It should show the page message', function() {
expect($scope.message).toEqual('This is the about page message from the controller');
});
});
});
【问题讨论】:
-
这里是项目存储库的链接,以防需要更多信息bitbucket.org/baylysoft/angular-seed-project
标签: javascript node.js angularjs gulp karma-jasmine