您可以在调用中将组件类型设置为
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();});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)