mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-27 20:06:36 +08:00
Merge branch 'feature/unit_test'
This commit is contained in:
commit
db494aaaa5
@ -38,4 +38,58 @@ describe('Search', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handle clean click', () => {
|
||||||
|
wrapper = mount(Search);
|
||||||
|
|
||||||
|
wrapper.setData({ value: 'test' });
|
||||||
|
expect(wrapper.data().value).to.be.equal('test');
|
||||||
|
|
||||||
|
const input = wrapper.find('.zan-search__input')[0];
|
||||||
|
input.simulate('focus');
|
||||||
|
|
||||||
|
const cleanBtn = wrapper.find('.zan-icon-clear')[0];
|
||||||
|
cleanBtn.simulate('click');
|
||||||
|
expect(wrapper.data().value).to.equal('');
|
||||||
|
expect(wrapper.data().focusStatus).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handle cancel click', (done) => {
|
||||||
|
wrapper = mount(Search);
|
||||||
|
|
||||||
|
wrapper.setData({ value: 'test' });
|
||||||
|
expect(wrapper.data().value).to.be.equal('test');
|
||||||
|
|
||||||
|
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
||||||
|
|
||||||
|
const input = wrapper.find('.zan-search__input')[0];
|
||||||
|
input.simulate('focus');
|
||||||
|
|
||||||
|
const cancelBtn = wrapper.find('.zan-search__cancel')[0];
|
||||||
|
cancelBtn.simulate('click');
|
||||||
|
|
||||||
|
wrapper.vm.$nextTick(() => {
|
||||||
|
expect(wrapper.data().value).to.be.equal('');
|
||||||
|
expect(wrapper.data().focusStatus).to.be.false;
|
||||||
|
expect(wrapper.data().isFocus).to.be.false;
|
||||||
|
expect(eventStub.calledOnce).to.be.true;
|
||||||
|
expect(eventStub.calledWith('change'));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('emit a search event', (done) => {
|
||||||
|
wrapper = mount(Search);
|
||||||
|
|
||||||
|
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
||||||
|
|
||||||
|
const input = wrapper.find('.zan-search__input')[0];
|
||||||
|
input.simulate('keyup.enter');
|
||||||
|
|
||||||
|
wrapper.vm.$nextTick(() => {
|
||||||
|
expect(eventStub.calledOnce).to.be.true;
|
||||||
|
expect(eventStub.calledWith('search'));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user