经过很多麻烦后,我让Jasmine在我的Yeoman / Angular设置上工作。现在,当我运行grunt serve
时,我看到一条消息显示Jasmine wasn't injected in your file
。另外在我的浏览器控制台中,我看到Jasmine未定义。我检查了this问题和this主题。在我的index.html
和karma.conf.js
中手动添加了文件,但没有运气。此外,在我执行grunt serve
后,这些地址将从我的index.html文件中删除。我的凉亭json也有茉莉花的入口。这些是我的文件:
karma.conf.js:
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2014-09-12 using
// generator-karma 0.8.3
module.exports = function(config) {
'use strict';
config.set({
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// base path, that will be used to resolve files and exclude
basePath: '../',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine-jquery', 'jasmine'],
// list of files / patterns to load in the browser
files: [
'bower_components/jasmine-jquery/lib/jasmine-jquery.js',
'bower_components/jasmine/lib/jasmine-core.js',
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-touch/angular-touch.js',
'bower_components/angular-bootstrap/ui-bootstrap.js',
'app/scripts/**/*.js',
//'test/mock/**/*.js',
'test/spec/**/*.js',
'app/views/*.html'
],
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
'PhantomJS'
],
// Which plugins to enable
plugins: [
'karma-phantomjs-launcher',
'karma-jasmine',
'karma-jasmine-jquery',
'karma-ng-html2js-preprocessor'
],
preprocessors: {
'app/views/*.html': 'ng-html2js'
},
ngHtml2JsPreprocessor: {
stripPrefix: 'app/',
moduleName: 'views'
},
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
colors: true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
// '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
});
};
bower.json:
{
"name": "yeosalt",
"version": "0.0.0",
"dependencies": {
"angular": "~1.2.0",
"json3": "~3.3.1",
"es5-shim": "~3.1.0",
"bootstrap-sass-official": "~3.2.0",
"angular-resource": "~1.2.0",
"angular-cookies": "~1.2.0",
"angular-sanitize": "~1.2.0",
"angular-animate": "~1.2.0",
"angular-touch": "~1.2.0",
"angular-route": "~1.2.0",
"angular-bootstrap": "~0.11.0",
"jasmine-jquery": "~2.0.5",
"jasmine": "~2.0.4"
},
"devDependencies": {
"angular-mocks": "~1.2.0",
"angular-scenario": "~1.2.0",
"jasmine-jquery": "~2.0.5"
},
"appPath": "app"
}
答案 0 :(得分:1)
根据我的经验," Jasmine没有注入您的档案"是由于你的bower.json配置。
以下行
"jasmine-jquery": "~2.0.5",
"jasmine": "~2.0.4"
需要在" devDependencies"而不是"依赖"因为它们仅用于测试目的。
如果您真的希望将它们置于"依赖关系"之后,grunt会警告您,在您特别将它们添加到您的grunt配置中之前,不会注入这些文件。
关于第二个问题(" jasmine未定义"),我也遇到过这个问题。 似乎羯磨版本在业力(https://github.com/velesin/jasmine-jquery/issues/168)之间存在问题。 在我的bower.json中我(不需要茉莉花):
"devDependencies": {
// ...
"jasmine-jquery": "~1.3.1"
},
在我的karma.conf.js中,我有文件顶部的配置:
files: [
'bower_components/jquery/dist/jquery.min.js',
'bower_components/jasmine-jquery/lib/jasmine-jquery.js',
// ...
]
然后我能够使用jasmine变量。
希望能帮助你。