Improving test coverage for LocaleSwitcher

This commit is contained in:
Jeff Avallone 2019-01-06 17:12:28 -05:00
parent 2a77792165
commit f14e018518

View File

@ -4,6 +4,9 @@ import { shallow } from 'enzyme';
import i18n from 'i18n'; import i18n from 'i18n';
import { LocaleSwitcher } from 'components/LocaleSwitcher'; import { LocaleSwitcher } from 'components/LocaleSwitcher';
// Ensure initial locale is always "en" during tests
jest.mock('./locale-to-available', () => jest.fn(() => 'en'));
describe('LocaleSwitcher', () => { describe('LocaleSwitcher', () => {
test('rendering', () => { test('rendering', () => {
const component = shallow( const component = shallow(
@ -24,4 +27,26 @@ describe('LocaleSwitcher', () => {
expect(i18n.changeLanguage).toHaveBeenCalledWith('other'); expect(i18n.changeLanguage).toHaveBeenCalledWith('other');
}); });
test('interface update from language change', () => {
const component = shallow(
<LocaleSwitcher />
);
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(
<LocaleSwitcher />
);
jest.spyOn(component, 'setState');
component.unmount();
i18n.emit('languageChanged', 'other');
expect(component.setState).not.toHaveBeenCalled();
});
}); });