test: press enter to search

This commit is contained in:
afc163 2018-05-26 17:03:07 +08:00
parent 12d0aedeca
commit ac4a9086a0

View File

@ -77,4 +77,14 @@ describe('Input.Search', () => {
expect(onSearch).toHaveBeenCalledTimes(1);
expect(onSearch).toBeCalledWith('search text');
});
it('should trigger onSearch when press enter', () => {
const onSearch = jest.fn();
const wrapper = mount(
<Search defaultValue="search text" onSearch={onSearch} />
);
wrapper.find('input').simulate('keydown', { key: 'Enter', keyCode: 13 });
expect(onSearch).toHaveBeenCalledTimes(1);
expect(onSearch).toBeCalledWith('search text');
});
});