【发布时间】:2017-06-13 10:32:41
【问题描述】:
我正在尝试使用酶和摩卡咖啡测试 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}})
})
})
实际上并没有编写测试,因为它在声明包装器时失败
错误信息:TypeError: _this.store.getState 不是函数
不知道问题出在哪里,也找不到任何解决此问题的方法!
任何帮助都会很棒!
【问题讨论】:
-
其实需要通过redux-store。您不能只创建一个常量并将其作为 store 传递。
标签: reactjs testing redux mocha.js enzyme