我的组件抛出错误(应该是)
function ProblemChild() {
throw new Error("Error thrown from problem child");
return <div>Error</div>; // eslint-disable-line
}
我的问题是..我该如何测试这个?
const wrapper = mount(<ProblemChild />);
类似这样的事情..
expect(wrapper).toThrow()
最佳答案
在回调中包裹安装。就像这样:
expect(() => mount(<ProblemChild />)).toThrow()
关于jestjs - 如何测试应该抛出错误的组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52283294/