我把茉莉花与我的gulp,karma,browserify等配置集成在一起,但对于我的生活,我无法弄清楚为什么没有定义茉莉花功能:
TypeError: expect(...).toEqual is not a function
我能找到的所有样本都要求karma.conf.js添加“jasmine”作为框架,我应该好好去。
这是我的karma.conf.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', 'mocha', 'sinon-chai', 'browserify'],
// list of files / patterns to load in the browser
files: [
'src/js/**/__tests__/*'
],
// 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: {
'src/js/**/__tests__/*': ['browserify']
},
browserify: {
debug: true,
extensions: ['.js', '.coffee', '.hbs']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['nyan'],
// 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,
// Helps to address an issue on TravisCI where activity can time out
browserNoActivityTimeout: 30000
});
};
package.json的相关部分:
"devDependencies": {
"browser-sync": "~2.2.2",
"browserify": "^9.0.3",
"browserify-shim": "^3.8.2",
"coffeeify": "~1.0.0",
"font-awesome": "~4.3.0",
"gulp": "^3.8.11",
"gulp-autoprefixer": "^2.1.0",
"gulp-changed": "^1.1.1",
"gulp-filesize": "0.0.6",
"gulp-iconfont": "^1.0.0",
"gulp-imagemin": "^2.2.1",
"gulp-minify-css": "~0.5.1",
"gulp-notify": "^2.2.0",
"gulp-rename": "^1.2.0",
"gulp-sass": "~1.3.3",
"gulp-sourcemaps": "^1.5.0",
"gulp-swig": "^0.7.4",
"gulp-uglify": "^1.1.0",
"gulp-util": "^3.0.4",
"handlebars": "^3.0.0",
"hbsfy": "~2.2.1",
"jasmine-core": "~2.3.4",
"karma": "^0.12.31",
"karma-browserify": "^4.0.0",
"karma-chrome-launcher": "^0.1.7",
"karma-coffee-preprocessor": "^0.2.1",
"karma-jasmine": "~0.3.5",
"karma-mocha": "^0.1.10",
"karma-nyan-reporter": "0.0.51",
"karma-sinon-chai": "^0.3.0",
"lodash": "^3.3.1",
"merge-stream": "^0.1.7",
"pretty-hrtime": "~1.0.0",
"require-dir": "^0.1.0",
"vinyl-source-stream": "~1.0.0",
"watchify": "^2.4.0"
},
简单的演示测试:
var $ = require('jquery');
var locator = require('../modules/locator.js');
describe('modules/locator.js', function () {
it('should equal hello', function () {
expect(locator).toEqual('hello');
});
});
失败,因为无法识别expect(...)。toEqual(..)作为函数。或者,非jasmine语法可以正常传递:
var $ = require('jquery');
var locator = require('../modules/locator.js');
describe('modules/locator.js', function () {
return it('should equal hello', function () {
return locator.should.equal('hello');
});
});