对于Redux,我是新手,我试图为容器创建一个TestUnit,该容器连接到呈现表的对话框。
在集装箱里我有:
。
集装箱:
import { ApplicationState } from '../ApplicationState';
import { connect } from 'react-redux';
import TabelDialog, { TabelDialogProps } from '../components/dialogs/TabelDialog';
import { acceptDisplay } from '../actions/displayActions';
const mapStateToProps=(
state: ApplicationState,
{ open, onClose }: TabelDialogProps)
=> {
return {
open,
onClose,
tableData: [
{
manufacturer: 'Samsung',
displayType: 'OLED',
},
{
manufacturer: 'LG',
displayType: 'OLED',
}
]
}
};
const mapDispatchToProps = {
onAccept: acceptDisplay
};
export default connect(mapStateToProps, mapDispatchToProps)(TabelDialog);测试尚未完成,需要进行调整:
const createMockStore = () => {
const store = {
getState: jest.fn(() => ({})),
dispatch: jest.fn(),
data: jest.fn()
}
const next = jest.fn()
const invoke = action => thunk(store)(next)(action)
return {store, next, invoke }
}
describe('Container test', () => {
it('should dispatch open', () => {
const store = createMockStore();
const wrapper = shallow(
<TabelDialog
open = {true}
data = {undefined}
onClose = {undefined}
onAccept = {undefined}
/>
);
expect(store).toHaveBeenCalled():
});
})我想打开,onClose和数据。我在正确的道路上吗?
安迪
发布于 2020-03-26 14:10:40
不确定这是否会解决你的问题,但可能会给你一些进展。似乎您还必须为组件提供存储。
const store = {...}
const wrapper = shallow(<TabelDialog store={store} ... />);https://stackoverflow.com/questions/60867184
复制相似问题