Skip to content

Commit

Permalink
Fix tests, test preventDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
smfoote committed Dec 28, 2017
1 parent d497898 commit ff19bd6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions __tests__/Typeahead-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,26 @@ describe('Typeahead', () => {

it('should select the highlightedIndex by calling resultsList.selectResult with the state\'s highlightedIndex', () => {
const { wrapper } = mountSetup();
const highlightedIndex = 3;
const evt = { preventDefault: jest.fn() };
wrapper.instance().resultsList.selectResult = jest.fn();
wrapper.setState({highlightedIndex: 3});
wrapper.find('TypeaheadInput').props().enterKeyPressed();
wrapper.setState({highlightedIndex});
wrapper.find('TypeaheadInput').props().enterKeyPressed(evt);
expect(wrapper.instance().resultsList.selectResult).toHaveBeenCalled();
expect(wrapper.instance().resultsList.selectResult).toHaveBeenCalledWith(wrapper.state().highlightedIndex);
expect(wrapper.instance().resultsList.selectResult).toHaveBeenCalledWith(highlightedIndex);
expect(evt.preventDefault).toHaveBeenCalledTimes(1);
expect(wrapper.state('highlightedIndex')).toBe(-1);
});

it('should not select a result or preventDefault if highlightedindex is -1 state\'s highlightedIndex', () => {
const { wrapper } = mountSetup();
const highlightedIndex = -1;
const evt = { preventDefault: jest.fn() };
wrapper.instance().resultsList.selectResult = jest.fn();
wrapper.setState({highlightedIndex});
wrapper.find('TypeaheadInput').props().enterKeyPressed(evt);
expect(wrapper.instance().resultsList.selectResult).toHaveBeenCalledTimes(0);
expect(evt.preventDefault).toHaveBeenCalledTimes(0);
expect(wrapper.state('highlightedIndex')).toBe(-1);
});
});

0 comments on commit ff19bd6

Please sign in to comment.