import { shallow } from 'enzyme' ; import React from 'react' ; import { mountWithIntl } from 'test_utils/enzyme_helpers' ; import { ErrorToast } from './error_toast' ; interface ErrorToastProps { error ? : Error ; title ? : string ; toastMessage ? : string ; } let openModal ; beforeEach ( ( ) => ( openModal = jest . fn ( ) ) ) ; function render ( props = { } ) { return ( < ErrorToast openModal = { openModal } error = { props . error || new Error ( 'error message' ) } title = { props . title || 'An error occured' } toastMessage = { props . toastMessage || 'This is the toast message' } i18nContext = { ( ) => ( { children } ) => < React . Fragment > { children } < /React.Fragment>}/ > ) ; } it ( 'renders matching snapshot' , ( ) => { expect ( shallow ( render ( ) ) ) . toMatchSnapshot ( ) ; } ) ; it ( 'should open a modal when clicking button' , ( ) => { const wrapper = mountWithIntl ( render ( ) ) ; expect ( openModal ) . not . toHaveBeenCalled ( ) ; wrapper . find ( 'button' ) . simulate ( 'click' ) ; expect ( openModal ) . toHaveBeenCalled ( ) ; } ) ; afterAll ( ( ) => { document . body . innerHTML = '' ; } ) ;