使用酶测试React组件。Typescript找不到实例方法

使用酶测试React组件。Typescript找不到实例方法,第1张

使用酶测试React组件。Typescript找不到实例方法

您可以在调用中将组件类型设置为

shallow
。这有点样板,但是它使类型安全。好处是包装器是类型安全的,而不仅仅是您拉出的实例。

import Component from './Component'// Wrapper will know the type of the component.const wrapper = enzyme.shallow<Component>(<Component {...props} />);it('does something', () => {  expect(wrapper.instance().someInstanceMethod(input)).toBe(true);  // You can also get the state from the wrapper.  expect(wrapper.state().someComponentState).toBeTruthy();});


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5666561.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存