“TypeError:expect(...)。to.have.been.calledWith不是一个函数”With Karma

时间:2016-10-18 20:35:15

标签: sinon chai karma-mocha

我有以下Karma Conf ...

var webpackConfig = require('./webpack.config.js');
webpackConfig.entry = {};
webpackConfig.plugins = [];
var globFlat = require('glob-flat');

// TODO: These are redundant with the webpack plugin...
var appFiles = globFlat.sync([
  './src/main/coffee/**/*.coffee'
]);
var styleFiles = globFlat.sync([
]);
var dependencyFiles = [
  'test-main.js',
  './src/main/typescripts/**/*.ts',
  'node_modules/angular-mocks/angular-mocks.js'
];
var testFiles = globFlat.sync([
  './test/main/webapp/**/*.coffee',
  './test/main/webapp/**/*.js'
]);

var files = dependencyFiles.concat(appFiles, styleFiles, testFiles);
module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['mocha', 'requirejs', 'chai-spies', 'chai', 'sinon', 'sinon-chai'],
    files: files,
    exclude: [ ],
    preprocessors: {
      './src/main/coffee/**/*.coffee': ['webpack'],
      './src/main/typescripts/**/*.ts': ['webpack'],
      './test/**/*.coffee': ['coffee']
    },
    webpack: webpackConfig,
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    concurrency: Infinity
  })
};

但是,当我运行一些测试时打破......

  

TypeError:expect(...)。to.have.been.calledWith不是函数

我不明白,因为我包括了sinon-chai

1 个答案:

答案 0 :(得分:1)

这里有几个问题......

  1. 订单 我目前的订单是['mocha', 'requirejs', 'chai-spies', 'chai', 'sinon', 'sinon-chai']。这是从右向左阅读,而不是从左到右。所以我需要改为['mocha', 'requirejs', 'chai-spies', 'sinon-chai', 'chai', 'sinon']。这样Sinon-chai就会在sinon和chai之后加载。

  2. RequireJS不适用于'sinon-chai'https://github.com/kmees/karma-sinon-chai/issues/11

  3. 我的决赛结束了...

    ['mocha', 'sinon-chai', 'chai', 'sinon']