Skip to content

Commit

Permalink
ListItem specs - refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
carloluis committed Dec 23, 2017
1 parent ded4e9e commit 71bbee7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 53 deletions.
93 changes: 41 additions & 52 deletions src/suggestor/__tests__/ListItem.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,77 +18,66 @@ describe('<ListItem/>', () => {
expect(tree).toMatchSnapshot();
});

it('hover snapshot', () => {
it('snapshot - hover', () => {
const tree = renderer.create(<ListItem {...PROPS} overItem />).toJSON();
expect(tree).toMatchSnapshot();
});
});

describe('ListItem component - item click', () => {
const component = shallow(<ListItem {...PROPS} />);
const event = {
stopPropagation: jest.fn()
};
describe('ListItem', () => {
const event = { stopPropagation: jest.fn() };
let component;

beforeEach(() => {
event.stopPropagation.mockReset();
PROPS.onItemClick.mockReset();
PROPS.onItemMouseEnter.mockReset();
component = shallow(<ListItem {...PROPS} />);
event.stopPropagation.mockClear();
});

it('should call handleClick', () => {
const handleClickSpy = jest.spyOn(component.instance(), 'handleClick');
component.instance().forceUpdate();
component.update();
describe('on click', () => {
let handleClickSpy;
beforeEach(() => {
handleClickSpy = jest.spyOn(component.instance(), 'handleClick');
component.instance().forceUpdate();
component.update();

component.find('li').simulate('click', event);
component.find('li').simulate('click', event);
});

expect(handleClickSpy).toBeCalled();
expect(PROPS.onItemClick).toBeCalled();
});
it('should call handleClick', () => {
expect(handleClickSpy).toBeCalled();
});

it('should stop event propagation', () => {
component.find('li').simulate('click', event);
it('should stop event propagation', () => {
expect(event.stopPropagation).toHaveBeenCalled();
});

expect(event.stopPropagation).toHaveBeenCalled();
it('should call props.onItemClick', () => {
expect(PROPS.onItemClick).toBeCalledWith(PROPS.item);
});
});

it('should call props.onItemClick', () => {
component.find('li').simulate('click', event);

expect(PROPS.onItemClick).toBeCalledWith(PROPS.item);
});
});
describe('on mouse enter', () => {
let handleMouseEnterSpy;
beforeEach(() => {
handleMouseEnterSpy = jest.spyOn(component.instance(), 'handleMouseEnter');
component.instance().forceUpdate();
component.update();

describe('ListItem component - mouse enter', () => {
const component = shallow(<ListItem {...PROPS} />);
const event = {
stopPropagation: jest.fn()
};
component.find('li').simulate('mouseEnter', event);
});

beforeEach(() => {
event.stopPropagation.mockReset();
PROPS.onItemMouseEnter.mockReset();
});

it('should call handleMouseEnter', () => {
const handleMouseEnterSpy = jest.spyOn(component.instance(), 'handleMouseEnter');
component.instance().forceUpdate();
component.update();

component.find('li').simulate('mouseEnter', event);

expect(handleMouseEnterSpy).toBeCalled();
});

it('should stop event propagation', () => {
component.find('li').simulate('mouseEnter', event);

expect(event.stopPropagation).toHaveBeenCalled();
});
it('should call handleMouseEnter', () => {
expect(handleMouseEnterSpy).toBeCalled();
});

it('should call props.onItemClick', () => {
component.find('li').simulate('mouseEnter', event);
it('should stop event propagation', () => {
expect(event.stopPropagation).toHaveBeenCalled();
});

expect(PROPS.onItemMouseEnter).toBeCalledWith(PROPS.index);
it('should call props.onItemClick', () => {
expect(PROPS.onItemMouseEnter).toBeCalledWith(PROPS.index);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ListItem/> hover snapshot 1`] = `
exports[`<ListItem/> snapshot - hover 1`] = `
<li
onClick={[Function]}
onMouseEnter={[Function]}
Expand Down

0 comments on commit 71bbee7

Please sign in to comment.