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(); + }); });