我一直在尝试(没有成功)为ErrorBoundary通过componentDidCatch生命周期方法处理错误的组件编写测试用例。尽管内部子组件产生的误差<ErrorBoundry>成分,<ErrorBoundry>不使有关错误代码,但故障组件的内容信息,如果它的工作是正确的。组件在生产/开发中按预期方式工作,但在由Jest / Enzyme执行测试以进行测试时,则无法正常工作。
测试错误:
PASS src/ErrorBoundary.test.js
? Console
console.error node_modules/fbjs/lib/warning.js:33
Warning: `value` prop on `input` should not be null. Consider using an empty string to clear the component or `undefined` for uncontrolled components.
in input (at ErrorBoundary.test.js:11)
in div (at ErrorBoundary.test.js:10)
in ComponentWithError (at ErrorBoundary.test.js:26)
in ErrorBoundry (created by WrapperComponent)
in WrapperComponent
console.log src/ErrorBoundary.test.js:29
<ErrorBoundry>
<ComponentWithError>
<div>
<input type="text" value={{...}} />
</div>
</ComponentWithError>
</ErrorBoundry>
Run Code Online (Sandbox Code Playgroud)
ErrorBoundry.js:
import React, { Component } from 'react'
import Raven …Run Code Online (Sandbox Code Playgroud)