【发布时间】:2020-02-05 06:35:49
【问题描述】:
我觉得我错过了什么。我正在尝试模拟一个功能组件,但它一直给我一个错误
如果我这样做
TestRenderer.create(
<FunctionalComponent/>
)
它给出了错误
Invariant Violation: FunctionalComponent(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.
如果我将它更改为基于类的组件,它就可以工作。
如何模拟功能组件?谢谢!
编辑:
我尝试模拟这个组件
const SampleComponent = () => {
return <View/>
}
它给出了错误,
但是这个
class SampleClassComponent extends Component {
render() {
return <View/>
}
}
没有
运行时出错
jests.mock('path/to/component')
【问题讨论】:
-
你能发布你的测试组件吗?
-
@Fricken Hamster 您在哪里找到您添加的附加代码的示例?
-
@Fricken Hamster 你有没有找到解决这个问题的方法?