mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-08-07 04:59:46 +08:00
[Improvement] Search: add test cases (#1200)
This commit is contained in:
parent
ea76607f35
commit
eba129b13c
35
packages/search/test/index.spec.js
Normal file
35
packages/search/test/index.spec.js
Normal file
@ -0,0 +1,35 @@
|
||||
import Search from '..';
|
||||
import { mount } from '@vue/test-utils';
|
||||
|
||||
test('listen input event', () => {
|
||||
const wrapper = mount(Search);
|
||||
const input = wrapper.find('input');
|
||||
input.element.value = '1';
|
||||
input.trigger('input');
|
||||
|
||||
expect(wrapper.emitted('input')[0][0]).toEqual('1');
|
||||
});
|
||||
|
||||
test('cancel search', () => {
|
||||
const wrapper = mount(Search, {
|
||||
propsData: {
|
||||
value: 'test',
|
||||
showAction: true
|
||||
}
|
||||
});
|
||||
|
||||
const cancel = wrapper.find('.van-search__cancel');
|
||||
cancel.trigger('click');
|
||||
expect(wrapper.emitted('input')[0][0]).toEqual('');
|
||||
expect(wrapper.emitted('cancel')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('emit a search event', () => {
|
||||
const wrapper = mount(Search);
|
||||
const input = wrapper.find('input');
|
||||
input.trigger('keypress.enter');
|
||||
input.trigger('keypress.a');
|
||||
|
||||
expect(wrapper.emitted('search')).toBeTruthy();
|
||||
expect(wrapper.emitted('keypress')).toBeTruthy();
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user