Skip to content

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Easybuoy committed Nov 18, 2019
1 parent 2da2e80 commit 4f86305
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 19 deletions.
9 changes: 8 additions & 1 deletion src/__mocks__/mock.js

Large diffs are not rendered by default.

18 changes: 2 additions & 16 deletions src/components/Common/MovieListDropdown.test.jsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
import React from 'react';
import { shallow, mount } from 'enzyme';
import { shallow } from 'enzyme';

import mock from '../../__mocks__/mock';
import { MovieListDropdown } from './MovieListDropdown';

const { getMovieMock, getMoviesMock } = mock;
describe('<MovieListDropdown />', () => {
const props = {

setMovieValue: jest.fn().mockResolvedValue([])
};

it('renders the MovieListDropdown component correctly', () => {
const wrapper = shallow(<MovieListDropdown {...props} />);
expect(wrapper).toMatchSnapshot();
});

it('should call the mock onChange function', () => {
const wrapper = mount(<MovieListDropdown {...props} />);
const event = {
target: {
name: 'pollName',
value: JSON.stringify({ title: '', url: '' })
}
};
wrapper.find('select').simulate('change', event);
expect(props.getMovie).toBeCalled();
});
});
4 changes: 2 additions & 2 deletions src/components/Common/Select.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { Select as StyledSelect } from '../../styles';

const Select = ({ value, onChange, defaultValue, items }) => {
export const Select = ({ value, onChange, defaultValue, items }) => {
return (
<StyledSelect value={value} onChange={onChange}>
<StyledSelect value={value} onChange={onChange} className="select">
<option defaultValue={defaultValue} disabled>
{defaultValue}
</option>
Expand Down
32 changes: 32 additions & 0 deletions src/components/Common/Select.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { shallow } from 'enzyme';

import mock from '../../__mocks__/mock';
import { Select } from './Select';

const { getItemsMock } = mock;
describe('<MovieListDropdown />', () => {
const props = {
value: jest.mock(),
onChange: jest.fn(),
defaultValue: jest.mock(),
items: getItemsMock
};

it('renders the MovieListDropdown component correctly', () => {
const wrapper = shallow(<Select {...props} />);
expect(wrapper).toMatchSnapshot();
});

it('should call the mock onChange function', () => {
const wrapper = shallow(<Select {...props} />);
const event = {
target: {
name: 'pollName',
value: JSON.stringify({ title: '', url: '' })
}
};
wrapper.find('.select').simulate('change', event);
expect(props.onChange).toBeCalled();
});
});
134 changes: 134 additions & 0 deletions src/components/Common/__snapshots__/Select.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<MovieListDropdown /> renders the MovieListDropdown component correctly 1`] = `
<styled.select
className="select"
onChange={[MockFunction]}
value={
Object {
"addMatchers": [Function],
"advanceTimersByTime": [Function],
"advanceTimersToNextTimer": [Function],
"autoMockOff": [Function],
"autoMockOn": [Function],
"clearAllMocks": [Function],
"clearAllTimers": [Function],
"deepUnmock": [Function],
"disableAutomock": [Function],
"doMock": [Function],
"dontMock": [Function],
"enableAutomock": [Function],
"fn": [Function],
"genMockFromModule": [Function],
"getTimerCount": [Function],
"isMockFunction": [Function],
"isolateModules": [Function],
"mock": [Function],
"requireActual": [Function],
"requireMock": [Function],
"resetAllMocks": [Function],
"resetModuleRegistry": [Function],
"resetModules": [Function],
"restoreAllMocks": [Function],
"retryTimes": [Function],
"runAllImmediates": [Function],
"runAllTicks": [Function],
"runAllTimers": [Function],
"runOnlyPendingTimers": [Function],
"runTimersToTime": [Function],
"setMock": [Function],
"setTimeout": [Function],
"spyOn": [Function],
"unmock": [Function],
"useFakeTimers": [Function],
"useRealTimers": [Function],
}
}
>
<option
defaultValue={
Object {
"addMatchers": [Function],
"advanceTimersByTime": [Function],
"advanceTimersToNextTimer": [Function],
"autoMockOff": [Function],
"autoMockOn": [Function],
"clearAllMocks": [Function],
"clearAllTimers": [Function],
"deepUnmock": [Function],
"disableAutomock": [Function],
"doMock": [Function],
"dontMock": [Function],
"enableAutomock": [Function],
"fn": [Function],
"genMockFromModule": [Function],
"getTimerCount": [Function],
"isMockFunction": [Function],
"isolateModules": [Function],
"mock": [Function],
"requireActual": [Function],
"requireMock": [Function],
"resetAllMocks": [Function],
"resetModuleRegistry": [Function],
"resetModules": [Function],
"restoreAllMocks": [Function],
"retryTimes": [Function],
"runAllImmediates": [Function],
"runAllTicks": [Function],
"runAllTimers": [Function],
"runOnlyPendingTimers": [Function],
"runTimersToTime": [Function],
"setMock": [Function],
"setTimeout": [Function],
"spyOn": [Function],
"unmock": [Function],
"useFakeTimers": [Function],
"useRealTimers": [Function],
}
}
disabled={true}
>
<Component />
</option>
<option
key="ALL"
me="ALL"
name="ALL"
value="{\\"title\\":\\"ALL\\"}"
>
ALL
</option>
<option
key="MALE"
me="MALE"
name="MALE"
value="{\\"title\\":\\"MALE\\"}"
>
MALE
</option>
<option
key="FEMALE"
me="FEMALE"
name="FEMALE"
value="{\\"title\\":\\"FEMALE\\"}"
>
FEMALE
</option>
<option
key="HERMAPHODITE"
me="HERMAPHODITE"
name="HERMAPHODITE"
value="{\\"title\\":\\"HERMAPHODITE\\"}"
>
HERMAPHODITE
</option>
<option
key="N/A"
me="N/A"
name="N/A"
value="{\\"title\\":\\"N/A\\"}"
>
N/A
</option>
</styled.select>
`;

0 comments on commit 4f86305

Please sign in to comment.