我有一个这样的组件:
<Parent>
<Child/>
</Parent>
和<Child/>
组件有一个方法foo
。我想测试 foo
方法,但我不知道如何访问它。我尝试过:
mount(<Parent><Child/></Parent>).props().children.foo
或
mount(<Parent><Child/></Parent>).children().foo
但它们都是undefined
。我无法使用.instance()
因为它不是根。我无法安装<Child/>
只因为<Parent>
在 context.router
上添加一些内容(react-router 的 context
)我在初始化时需要它们 <Child/>
。对此有什么想法吗?
最佳答案
这对我有用:
mount(<Parent><Child/></Parent>).find(Child).instance().foo
关于javascript - 如何用Enzyme测试子成分法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42245215/