我在茉莉花测试中使用了proxyquire这个模拟插件。用茉莉花运行测试很不错,并且测试通过了。但是,使用Karma运行测试时出现以下错误: 我尝试在插件中添加proxyquire,但出现错误。
TypeError:proxyquire不是函数
我的业力设置:
config.set({
basePath: '',
frameworks: ['jasmine', 'browserify'],
files: [
'src/**/**/*.spec.js'
],
exclude: [
'node_module/**/*.js'
],
preprocessors: {
'**/*.spec.js': ['browserify']
},
plugins: ['karma-browserify', 'karma-jasmine', 'karma-chrome-launcher'],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
我的测试如下:
const proxyquire = require('proxyquire');
const data = require('./data.json');
describe('usage report', () => {
let target = null;
const mockValue = '12345';
beforeEach(() => {
target = proxyquire('./../index.js', { './usage': () => mockValue });
});
it('should return an array', () => {
const actual = target(data);
expect(actual).not.toBe(undefined);
expect(actual.length).toEqual(data.electricity.length);
});
});