Javascript 业力和茉莉花:测试不识别任何茉莉花功能

Javascript 业力和茉莉花:测试不识别任何茉莉花功能,javascript,jasmine,karma-runner,karma-jasmine,Javascript,Jasmine,Karma Runner,Karma Jasmine,我将jasmine与我的吞咽、因果报应、browserify等配置相结合,但就我而言,我无法理解为什么jasmine函数没有定义: TypeError:expect(…)。toEqual不是一个函数 我能找到的所有示例都要求karma.conf.js添加“jasmine”作为框架,我应该可以开始了 这是我的karma.conf.js: module.exports = function(config) { config.set({ // base path that will be

我将jasmine与我的吞咽、因果报应、browserify等配置相结合,但就我而言,我无法理解为什么jasmine函数没有定义:

TypeError:expect(…)。toEqual不是一个函数

我能找到的所有示例都要求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');
    });
});

摩卡咖啡和茉莉花正在尝试完成同样的事情(都是测试跑步者)。如果不仔细观察,可能是因为您将
mocha
jasmine
都作为框架。Doh!那正是它的本来面目。谢谢@NickTomlin。