렌더링한 컴포넌트 클래스 메서드를 사용하고 싶을 경우

const Wrapper = shallow(<MyComponent />);

Wrapper.instance().myMethod() 와 같이 쓰면 되는데

typescript를 사용하고 있다면 린트에서 에러를 발생시킨다.


const instance = Wrapper.instance() as MyComponent;

instance.myMethod();

와 같이 캐스팅해서 쓰면 된다.


+ Recent posts