Убедитесь, что функция успешно вызвана в JEST - PullRequest
0 голосов
/ 22 апреля 2020

Файл компонента

const ErrorSnackbar = () => {
const {
        primaryActionType,
        onPrimaryBtnClick = () => { }
    } = errorSnackbar

 const handelePrimaryBtnClick = () => {
      if (primaryActionType === 'custom') onPrimaryBtnClick()
    }

return (
        <div className={`notification`}>
            <div className='text'>
                <p className="desc">{title}</p>
                <div className='snackbar___action ripple rect' onClick={handelePrimaryBtnClick}>                        Just Some Text </div>
            </div>
        </div>
    )
}

Файл теста компонента:

test('Testing the component', () => {
        context = {errorSnackbar: {primaryActionType : 'custom'} }
        wrapper = mount(
            <Provider value={{ ...context }} >
                <ErrorSnackbar />
            </Provider>)
        wrapper.update();
        wrapper.find('.notification .text .snackbar___action').simulate('click', {target: {name: 0}})
}

Как я могу подтвердить, что при нажатии div метод onPrimaryBtnClick () успешно вызывается?

...