我试图将一个组件渲染到Mocha中,并且我不知道为什么会出现此错误:
任何人都知道为什么会这样?我手动传递道具,因为当自己包装自己的容器时,Enzyme并没有真正覆盖connect()。
import chai from 'chai'
import React from 'react'
import { shallow, props } from 'enzyme'
import sinon from 'sinon'
import PureTestNest from '../../components/CounterNest'
import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store'
import sinonChai from 'sinon-chai'
const expect = chai.expect;
chai.use(sinonChai);
function setup(value = 0) {
const component = shallow(
<PureTestNest value={value} doIncreaseNumber={doIncreaseNumber} store={store} />
)
let doIncreaseNumber = sinon.spy()
return {
component: component,
doIncreaseNumber,
buttons: component.find('button')
}
}
const middlewares = [thunk]
let mockStore = configureStore(middlewares)
let component;
const getState = {}
const store = mockStore(getState)
describe('Components --CounterNest', () => {
it('should increment an value on a click', () => {
const { buttons, doIncreaseNumber } = setup()
buttons.at(0).simulate('click')
expect(doIncreaseNumber).to.have.been.called()
});
});
答案 0 :(得分:1)
在组件中使用间谍之前创建间谍?
function setup(value = 0) {
let doIncreaseNumber = sinon.spy()
const component = shallow(
<PureTestNest value={value} doIncreaseNumber={doIncreaseNumber} store={store} />
)
return {
component: component,
doIncreaseNumber,
buttons: component.find('button')
}
}
我不熟悉Mocha(Jasmine用户)