我正在尝试使用mocha js为我的反应代码编写测试脚本。测试助手文件是这样的 browser.js
var baseDOM = '<!DOCTYPE html><html><head><meta charset="utf-8"></head><body></body></html>';
var jsdom = require('jsdom').jsdom;
global.document = jsdom(baseDOM);
global.window = document.defaultView;
if ( global.self != null) {
console.log(' global.self >>>>> ' + global.self);
} else {
global.self = global.this;
}
global.navigator = {
userAgent: 'node.js'
};
测试脚本就像这样(component.specs.js)
'use strict';
import ReactDOM from 'react-dom';
import React from 'react';
import { expect } from 'chai';
import { mount, shallow, render } from 'enzyme';
import { App } from '../../js/app.js';
import sinon from 'sinon';
var dispatch = function() {
`enter code here` console.log('>>>>>>>> Mocking dispatch ');
};
describe('App', function () {
it('App calls check', () => {
sinon.spy(App.prototype, 'check');
const enzymeWrapper = mount(<App {...props} />);
expect(App.prototype.check.calledOnce).to.equal(true);
});
所以,当我运行npm test时,我得到的错误是&#39; jsdom不是函数&#39;。代码有什么问题?
答案 0 :(得分:1)