jjzjj

WrappedComponent

全部标签

javascript - Jest Enzyme 如何对包装组件的存在进行浅层测试

我正在测试一个有条件地呈现包装组件的组件。我正在使用enzyme和jest,根组件是通过shallow()方法呈现的。问题是测试Root组件是否包含包装组件。如何在不使用mount()渲染方法的情况下测试包装组件是否存在?hoc.component.jsxexportfunctionHOC(Component){render(){return}}wrapped.component.jsxclassWrappedComponentextendsReact.Component{...}exportdefaultHOC(WrappedComponent)root.component.jsxc

javascript - 使用 enzyme 和 TypeScript 的浅层 HOC

我有一个HOC要测试,在浅挂载期间我应该调用一些类方法:it('Shouldnotcalldispatch',()=>{constdispatch=jest.fn()constWrappedComponent=someHoc(DummyComponent)constinstance=shallow(,).instance()asWrappedComponentinstance.someMethod()expect(dispatch).toHaveBeenCalledTimes(0)})测试工作正常但TS编译器抛出错误Cannotfindname'WrappedComponent'.这是