From f14e018518edefaa14747b50d735edb4722aa03f Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Sun, 6 Jan 2019 17:12:28 -0500 Subject: [PATCH] Improving test coverage for LocaleSwitcher --- src/components/LocaleSwitcher/test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/components/LocaleSwitcher/test.js b/src/components/LocaleSwitcher/test.js index eb2b17a..77ac016 100644 --- a/src/components/LocaleSwitcher/test.js +++ b/src/components/LocaleSwitcher/test.js @@ -4,6 +4,9 @@ import { shallow } from 'enzyme'; import i18n from 'i18n'; import { LocaleSwitcher } from 'components/LocaleSwitcher'; +// Ensure initial locale is always "en" during tests +jest.mock('./locale-to-available', () => jest.fn(() => 'en')); + describe('LocaleSwitcher', () => { test('rendering', () => { const component = shallow( @@ -24,4 +27,26 @@ describe('LocaleSwitcher', () => { expect(i18n.changeLanguage).toHaveBeenCalledWith('other'); }); + + test('interface update from language change', () => { + const component = shallow( + + ); + + expect(component.find('select').prop('value')).toEqual('en'); + i18n.emit('languageChanged', 'other'); + expect(component.find('select').prop('value')).toEqual('other'); + }); + + test('disconnecting event handler on unmount', () => { + const component = shallow( + + ); + + jest.spyOn(component, 'setState'); + + component.unmount(); + i18n.emit('languageChanged', 'other'); + expect(component.setState).not.toHaveBeenCalled(); + }); });