我从create-react-app开始了我的项目,但是自从添加Django后端以来,我已经转到了webpack。我没有更改任何测试,但其中大多数不再通过。这是测试失败的示例
it("moving elements to dragAttrCircle and clicking gets to next shape", () => {
const wrapper = mount(<Provider store={store}> <ShowShape/></Provider>,{ attachTo: window.domNode });
wrapper.find('.flipHolder').simulate('click')
wrapper.find('.flipHolder').simulate('click')
expect(wrapper.find(Instructions).find('#instructions').text()).to.match(/^Drag the items from the right to the appropriate location on the left Circle/)
let circleWrapper = wrapper.find(CircleElements)
let arrowVisibility = circleWrapper.find('.arrows').at(0).find('g').find('line').get(0).props.style
expect(arrowVisibility).to.have.property('display', 'none');
circleWrapper.find("Draggable").at(0).simulate("mousedown");
circleWrapper.find("Draggable").at(0).simulate("mouseup");
circleWrapper.find("Draggable").at(1).simulate("mousedown");
circleWrapper.find("Draggable").at(1).simulate("mouseup");
circleWrapper.find("Draggable").at(2).simulate("mousedown");
circleWrapper.find("Draggable").at(2).simulate("mouseup");
circleWrapper.find("Draggable").at(3).simulate("mousedown");
circleWrapper.find("Draggable").at(3).simulate("mouseup");
expect(wrapper.find(Instructions).find('#instructions').text()).to.match(/^click again to see the next shape/)
let reduxState = wrapper.state().store.getState();
expect(reduxState.snapReducer.snapped).to.deep.equal([ true, true, true, true ]);})
我得到了错误:
ReactWrapper::state() can only be called on class components
但是,当我使用create-react-app测试方法时,没有出现该错误。这是我目前在package.json中配置测试的方式
"scripts": {"test": "jest",