reactjs - 重定向类中断终端 - 测试
问题描述
我正在尝试使用 Jest 和 Ezyme 运行测试
Editworkflow 是一种状态,它正在重定向到另一个位置。如果我将它设置为 true,它会破坏终端。
经过一些研究,我能够做到以下几点
describe("when user has permission", () => {
beforeEach(() => {
wrapper.setState({editWorkflow: true, selectedWorkId:true });
wrapper.instance().history.replace('/add'); // replace the MemoryRouter location with
wrapper.update(); // update the wrapper with the changes
})
it("Test click event on Workflows - Cancel/AddWork", () => {
baseProps.onClick.mockClear();
expect(wrapper.containsMatchingElement(<Redirect to="/add" />)).toEqual(true)
expect(wrapper.containsMatchingElement(<Redirect to="/edit/" />)).toEqual(true)
wrapper.find('Workflows').find('#add-work-button').at(0).simulate("click");
wrapper.find('Workflows').find('#add-work-button').at(1).simulate("click");
);
目前终端没有损坏,但测试也没有通过。
这是错误:
expect(received).toEqual(expected)
Expected value to equal:
true
Received:
false
expect(wrapper.containsMatchingElement(<Redirect to="/add"/>)).toEqual(true)
如果我将上面的语句设置为 False,则终端再次中断
这是状态调用重定向的地方
{ this.state.editWorkflow ? <Redirect push to={`${this.props.location.pathname}/add`} /> : null }
{ this.state.selectedWorkId ? <Redirect push to={`${this.props.location.pathname}/edit/${this.state.selectedWorkId}`} /> : null }
我如何使用 Jest 和 Enzyme 编写以下测试并防止这种情况发生
解决方案
推荐阅读
- c++ - 如何为链表实现 end()?
- c - 如何每分钟标记一个时间戳?
- c++ - 编译器无法识别在类声明之外定义的方法
- asp.net - Asp.net MVC 多行表单控件/文本框
- javascript - 页面不断重新加载,而不是生成时间的 setinterval
- qt - 如何从 QListWidgetItem 中删除所有项目?
- javascript - 无法在 stackblitz 中迭代 Javascript 集?
- flutter - 如何从字符串路径中获取文件扩展名
- python - 在 Python Session 中,我如何知道要在运行时发布到 Request Payload 的字段?
- r - 在 gganimate 的 transition_reveal 的标题表达式中使用替代变量?