2014-09-16 2 views
0

После многих неприятностей я получил Жасмин, работающий над моей установкой Йоман/Угловая. Теперь, когда я запускаю grunt serve, я вижу сообщение, которое сообщает Jasmine wasn't injected in your file. Кроме того, в моей консоли браузера я вижу, что Jasmine не определен. Я проверил this выпуск и this нить. Включил файлы вручную в мои index.html и karma.conf.js, но не повезло. Кроме того, после выполнения grunt serve эти адреса удаляются из моего файла index.html. У моей беседы тоже есть запись для жасмина. Это мои файлы:Жасмин не был введен в мой файл?

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" 
} 

ответ

1

В моем опыте "Жасмин не вводили в файл" из-за конфигурации bower.json.

Следующие строки

"jasmine-jquery": "~2.0.5", 
"jasmine": "~2.0.4" 

нужно быть под «devDependencies», а не «зависимостей», потому что они используются только для целей тестирования.

Если вы действительно хотите, чтобы они находились под «зависимостями», grunt предупредит вас, что файлы не вводятся до тех пор, пока вы не добавите их в свою конфигурацию grunt.

О второй проблеме («жасмин не определен»), я также получил эту проблему один раз. Кажется, что существует проблема между версией жасмина в карме (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', 
    // ... 
] 

И тогда я был в состоянии для использования переменной жасмина.

Надеюсь, что это поможет.