From 54b48f5581914ff09e0bf92c26f90af599e27732 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Fri, 8 Jun 2018 21:05:35 -0400 Subject: [PATCH] Improving test coverage --- src/components/Form/test.js | 7 ++++++- .../LocaleSwitcher/__snapshots__/test.js.snap | 15 ++++++++++++++- src/components/LocaleSwitcher/index.js | 8 +++----- src/components/LocaleSwitcher/test.js | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/components/Form/test.js b/src/components/Form/test.js index 4a142ce..4e4b6fe 100644 --- a/src/components/Form/test.js +++ b/src/components/Form/test.js @@ -42,8 +42,13 @@ describe('Form', () => { const component = shallow(
); + + const exprInput = component.find('[name="expr"]'); + const syntaxInput = component.find('[name="syntax"]'); + exprInput.simulate('change', { target: { name: 'expr', value: 'Test expression' } }); + syntaxInput.simulate('change', { target: { name: 'syntax', value: 'test' } }); + const eventObj = { preventDefault: jest.fn() }; - component.setState({ syntax: 'test', expr: 'Test expression' }); component.find('form').simulate('submit', eventObj); expect(eventObj.preventDefault).toHaveBeenCalled(); diff --git a/src/components/LocaleSwitcher/__snapshots__/test.js.snap b/src/components/LocaleSwitcher/__snapshots__/test.js.snap index 3b4a583..795b464 100644 --- a/src/components/LocaleSwitcher/__snapshots__/test.js.snap +++ b/src/components/LocaleSwitcher/__snapshots__/test.js.snap @@ -11,7 +11,20 @@ exports[`LocaleSwitcher rendering 1`] = ` diff --git a/src/components/LocaleSwitcher/index.js b/src/components/LocaleSwitcher/index.js index 6c8acbc..c7c5114 100644 --- a/src/components/LocaleSwitcher/index.js +++ b/src/components/LocaleSwitcher/index.js @@ -26,8 +26,6 @@ class LocaleSwitcher extends React.PureComponent { current: localeToAvailable(i18n.language || '', Object.keys(locales), 'en') } - localeSelector = React.createRef() - componentDidMount() { i18n.on('languageChanged', this.handleLanguageChange); } @@ -36,8 +34,8 @@ class LocaleSwitcher extends React.PureComponent { i18n.off('languageChanged', this.handleLanguageChange); } - handleSelectChange = () => { - i18n.changeLanguage(this.localeSelector.current.value); + handleSelectChange = ({ target }) => { + i18n.changeLanguage(target.value); } handleLanguageChange = lang => { @@ -50,7 +48,7 @@ class LocaleSwitcher extends React.PureComponent { return