Fix AnsibleSelect tests

This commit is contained in:
Marliana Lara
2019-02-19 16:14:28 -05:00
parent 740a9c1e61
commit 8be8663665

View File

@@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme'; import { mount } from 'enzyme';
import { I18nProvider } from '@lingui/react';
import AnsibleSelect from '../../src/components/AnsibleSelect'; import AnsibleSelect from '../../src/components/AnsibleSelect';
const label = 'test select'; const label = 'test select';
@@ -7,6 +8,7 @@ const mockData = ['/venv/baz/', '/venv/ansible/'];
describe('<AnsibleSelect />', () => { describe('<AnsibleSelect />', () => {
test('initially renders succesfully', async () => { test('initially renders succesfully', async () => {
mount( mount(
<I18nProvider>
<AnsibleSelect <AnsibleSelect
value="foo" value="foo"
name="bar" name="bar"
@@ -14,12 +16,14 @@ describe('<AnsibleSelect />', () => {
label={label} label={label}
data={mockData} data={mockData}
/> />
</I18nProvider>
); );
}); });
test('calls "onSelectChange" on dropdown select change', () => { test('calls "onSelectChange" on dropdown select change', () => {
const spy = jest.spyOn(AnsibleSelect.prototype, 'onSelectChange'); const spy = jest.spyOn(AnsibleSelect.prototype, 'onSelectChange');
const wrapper = mount( const wrapper = mount(
<I18nProvider>
<AnsibleSelect <AnsibleSelect
value="foo" value="foo"
name="bar" name="bar"
@@ -27,6 +31,7 @@ describe('<AnsibleSelect />', () => {
label={label} label={label}
data={mockData} data={mockData}
/> />
</I18nProvider>
); );
expect(spy).not.toHaveBeenCalled(); expect(spy).not.toHaveBeenCalled();
wrapper.find('select').simulate('change'); wrapper.find('select').simulate('change');
@@ -35,6 +40,7 @@ describe('<AnsibleSelect />', () => {
test('Returns correct select options if defaultSelected props is passed', () => { test('Returns correct select options if defaultSelected props is passed', () => {
const wrapper = mount( const wrapper = mount(
<I18nProvider>
<AnsibleSelect <AnsibleSelect
value="foo" value="foo"
name="bar" name="bar"
@@ -43,6 +49,7 @@ describe('<AnsibleSelect />', () => {
data={mockData} data={mockData}
defaultSelected={mockData[1]} defaultSelected={mockData[1]}
/> />
</I18nProvider>
); );
expect(wrapper.find('FormSelect')).toHaveLength(1); expect(wrapper.find('FormSelect')).toHaveLength(1);
}); });