我试图用酶和摩卡来测试一个 React 组件,如下所示
import { mount, shallow } from 'enzyme';
import React from 'react';
import chai, { expect } from 'chai'
import chaiEnzyme from 'chai-enzyme'
import sinon from 'sinon'
import MyComponent from 'myComponent'
chai.use(chaiEnzyme())
describe('MyComponent', () => {
const store = {
id: 1
}
it ('renders', () => {
const wrapper = mount(<MyComponent />, {context: {store: store}})
})
})
Run Code Online (Sandbox Code Playgroud)
实际上还没有编写测试,因为它在包装器的声明中失败了
错误信息:TypeError: _this.store.getState is not a function
不知道问题是什么,也找不到任何解决此问题的方法!
任何帮助都会很棒!