Commit f14e0185 authored by Jeff Avallone's avatar Jeff Avallone

Improving test coverage for LocaleSwitcher

parent 2a777921
Pipeline #42336027 passed with stage
in 54 seconds
......@@ -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(
<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();
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment