Unit testing 如何测试动作道具中的反应成分与酶的反应
我正在开发一个使用Unit testing 如何测试动作道具中的反应成分与酶的反应,unit-testing,meteor,reactjs,enzyme,mantrajs,Unit Testing,Meteor,Reactjs,Enzyme,Mantrajs,我正在开发一个使用ReactiveDict的应用程序。我的项目是建立与流星,与咒语规范 我有一个名为Login的React组件。概念是,当组件渲染时,ReactiveDict状态被清除,因为组件渲染时没有错误。不过那很好。我的容器中有以下代码: export const depsMapper = (context, actions) => ({ context: () => context, loginUser:actions.login.loginUser, clear
ReactiveDict
的应用程序。我的项目是建立与流星,与咒语规范
我有一个名为Login
的React组件。概念是,当组件渲染时,ReactiveDict
状态被清除,因为组件渲染时没有错误。不过那很好。我的容器中有以下代码:
export const depsMapper = (context, actions) => ({
context: () => context,
loginUser:actions.login.loginUser,
clearState: actions.globals.clearState
});
这些是组件将执行的操作。在我的组件中:
componentWillMount(){
this.props.clearState('LOGIN_ERROR_MESSAGE');
}
最后,在我的测试代码中,我有:
it.only('should render a <Form/> component', () => {
const loginWrapper = shallow(<Login/>);
expect(loginWrapper.find(Form)).to.have.length(1);
});
it.only('应该呈现组件',()=>{
const loginWrapper=shallow();
expect(loginWrapper.find(Form)).to.have.length(1);
});
当我运行npm测试时,它说,
this.props.clearState
不是一个函数。我该怎么修这个?提前谢谢。我想在卸载时清除错误更方便吗?ReactiveDict无论如何都不是持久性的,因此-卸载时清除状态-如果刷新页面或卸载组件,错误将被清除。因此,没有理由在安装前清除状态。通常,您会在mantrajs中执行以下操作:
export const composer = ({context, clearState}, onData) => {
const {LocalState} = context();
const error = LocalState.get('LOGIN_ERROR_MESSAGE');
onData(null, {error});
// return the function that clears the state and the state gets reset on unmount
return clearState;
};
export const depsMapper = (context, actions) => ({
context: () => context,
loginUser: actions.login.loginUser,
clearState: actions.globals.clearState
});
export default composeAll(
composeWithTracker(composer),
useDeps(depsMapper)
)(Login);
我认为卸载时清除错误更方便吗?ReactiveDict无论如何都不是持久性的,因此-卸载时清除状态-如果刷新页面或卸载组件,错误将被清除。因此,没有理由在安装前清除状态。通常,您会在mantrajs中执行以下操作:
export const composer = ({context, clearState}, onData) => {
const {LocalState} = context();
const error = LocalState.get('LOGIN_ERROR_MESSAGE');
onData(null, {error});
// return the function that clears the state and the state gets reset on unmount
return clearState;
};
export const depsMapper = (context, actions) => ({
context: () => context,
loginUser: actions.login.loginUser,
clearState: actions.globals.clearState
});
export default composeAll(
composeWithTracker(composer),
useDeps(depsMapper)
)(Login);