Как проверить метод вложенного компонента в жизненном цикле с энзимом / шуткой? - PullRequest
0 голосов
/ 29 марта 2020

В этих жизненных циклах (componentDidMount & ComponentDidUpdate) я хочу увидеть, вызывается ли myMethod. Эта функция создает HO C, украшает его другим HO C (WithFeature - здесь не детализировано - который использует хранилище редуксов);

WithMyMethod. js

export default page => WrappedComponent => {
  class WithMyMethod extends React.Component {
    componentDidMount() {
      if (this.props.isFeatureEnabled) {
        this.myMethod();
      }
    }

    componentDidUpdate(prevProps) {
      if (this.props.isFeatureEnabled && page === 'Home') {
        this.myMethod();
      }
    }

    myMethod() {
    // code
    }

    render() {
      return <WrappedComponent {...this.props)} />;
    }
  }

  return WithFeature('featureName')(WithMyMethod);
};

__ tests __ / WithMyMethod

В своих тестах я использую mount из фермента для использования жизненных циклов.

const TestComponent = () => null;
const WithMyMethodComponent = withMyMethod('Home')(TestComponent);

describe('withMyMethod', () => {
  test('when feature is enabled', () => {

    const wrapper = mount(
      <Provider store={getContext(stateWithFeatureEnabled)}>
        <WithMyMethodComponent />
      </Provider>,
    );

    // from here, how can I spy on 'myMethod' to check if it was invoked or not ?
  });
});

Спасибо заблаговременно!

...