【问题标题】:"TypeError: expect(...).to.have.been.calledWith is not a function" With Karma“TypeError:expect(...).to.have.been.calledWith 不是函数”与 Karma
【发布时间】:2016-10-18 20:35:15
【问题描述】:

我有以下 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.callWith 不是函数

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

【问题讨论】:

  • 我们可以看看一些测试代码吗?
  • 其实我提供的代码已经足够了,我会在一秒钟内给出答案。

标签: sinon chai karma-mocha


【解决方案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

我的最终结果是......

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    • 2017-05-12
    • 2017-08-10
    • 2015-12-06
    • 1970-01-01
    • 2019-12-31
    相关资源
    最近更新 更多