class component のテストは spy で書ける

2021/3/29
react preact preact-router
class A {
  componentWillMount() {}
  componentWillUnmount() {}
  render(){ return <div />; }
 }
const componentWillMount = spyOn(A.prototype, 'componentWillMount');
const componentWillUnmount = spyOn(A.prototype, 'componentWillUnmount');
mount(
  <Router>
    <A path="/foo" />
  </Router>
);
expect(componentWillMount).not.toHaveBeenCalled();
act(() => {
  route('/foo');
});