[new feature] Search: support input native events (#451)

This commit is contained in:
neverland
2017-12-19 10:24:56 +08:00
committed by GitHub
parent 48b2026e33
commit 79a2b13b63
7 changed files with 53 additions and 30 deletions

View File

@@ -52,8 +52,18 @@ describe('Search', () => {
it('handle clean click and refocus', (done) => {
wrapper = mount(Search);
wrapper.setProps({ value: 'test' });
const eventStub = sinon.stub(wrapper.vm, '$emit');
let value = 'test';
wrapper.setProps({ value });
const focusSpy = sinon.spy();
wrapper.vm.$on('focus', focusSpy);
const inputSpy = sinon.spy();
wrapper.vm.$on('input', val => {
value = val;
inputSpy();
});
const input = wrapper.find('.van-search__input')[0];
input.trigger('focus');
@@ -62,8 +72,9 @@ describe('Search', () => {
cleanBtn.trigger('click');
wrapper.vm.$nextTick(() => {
expect(eventStub.calledOnce).to.be.true;
expect(eventStub.calledWith('input')).to.be.true;
expect(focusSpy.calledOnce).to.be.true;
expect(inputSpy.calledOnce).to.be.true;
expect(value).to.equal('');
done();
});
});
@@ -89,19 +100,20 @@ describe('Search', () => {
});
});
it('emit a search event', (done) => {
it('emit a search event', () => {
wrapper = mount(Search);
const eventStub = sinon.stub(wrapper.vm, '$emit');
const searchSpy = sinon.spy();
wrapper.vm.$on('search', searchSpy);
const input = wrapper.find('.van-search__input')[0];
input.trigger('keypress.enter');
expect(searchSpy.calledOnce).to.be.true;
wrapper.vm.$nextTick(() => {
expect(eventStub.calledOnce).to.be.true;
expect(eventStub.calledWith('search'));
done();
});
const keypressSpy = sinon.spy();
wrapper.vm.$on('keypress', keypressSpy);
input.trigger('keypress.a');
expect(keypressSpy.calledOnce).to.be.true;
});
it('blur after click outside', () => {