mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
NumberKeyboard: fix test cases fail
This commit is contained in:
parent
9ada169058
commit
c4f11baf7c
19
test/unit/components/number-keyboard.vue
Normal file
19
test/unit/components/number-keyboard.vue
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<template>
|
||||||
|
<keep-alive>
|
||||||
|
<van-number-keyboard v-if="showKeyboard" />
|
||||||
|
</keep-alive>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import NumberKeyboard from 'packages/number-keyboard';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'number-keyboard-test',
|
||||||
|
|
||||||
|
components: {
|
||||||
|
[NumberKeyboard.name]: NumberKeyboard
|
||||||
|
},
|
||||||
|
|
||||||
|
props: ['showKeyboard']
|
||||||
|
};
|
||||||
|
</script>
|
@ -1,17 +1,12 @@
|
|||||||
import NumberKeyboard from 'packages/number-keyboard';
|
import NumberKeyboard from 'packages/number-keyboard';
|
||||||
|
import NumberKeyboardKeepAlive from '../components/number-keyboard';
|
||||||
import { mount } from 'avoriaz';
|
import { mount } from 'avoriaz';
|
||||||
import { triggerTouch } from '../utils';
|
import { triggerTouch } from '../utils';
|
||||||
|
|
||||||
function mockKeyDown(wrapper, keyIndex) {
|
function mockKeyDown(wrapper, keyIndex) {
|
||||||
const customEvent = document.createEvent('CustomEvent');
|
const customEvent = document.createEvent('CustomEvent');
|
||||||
customEvent.initCustomEvent('touchstart', true, true, {});
|
customEvent.initCustomEvent('touchstart', true, true, {});
|
||||||
Object.defineProperty(customEvent, 'target', {
|
wrapper.element.dataset.key = keyIndex;
|
||||||
value: {
|
|
||||||
dataset: {
|
|
||||||
key: keyIndex
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
wrapper.element.dispatchEvent(customEvent);
|
wrapper.element.dispatchEvent(customEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,11 +77,12 @@ describe('NumberKeyboard', () => {
|
|||||||
const show = sinon.spy();
|
const show = sinon.spy();
|
||||||
wrapper.vm.$on('show', show);
|
wrapper.vm.$on('show', show);
|
||||||
wrapper.vm.show = true;
|
wrapper.vm.show = true;
|
||||||
|
wrapper.trigger('animationend');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(show.calledOnce).to.be.true;
|
expect(show.calledOnce).to.be.true;
|
||||||
done();
|
done();
|
||||||
}, 800);
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('listen to show event when no transtion', (done) => {
|
it('listen to show event when no transtion', (done) => {
|
||||||
@ -118,11 +114,12 @@ describe('NumberKeyboard', () => {
|
|||||||
const hide = sinon.spy();
|
const hide = sinon.spy();
|
||||||
wrapper.vm.$on('hide', hide);
|
wrapper.vm.$on('hide', hide);
|
||||||
wrapper.vm.show = false;
|
wrapper.vm.show = false;
|
||||||
|
wrapper.trigger('animationend');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(hide.calledOnce).to.be.true;
|
expect(hide.calledOnce).to.be.true;
|
||||||
done();
|
done();
|
||||||
}, 800);
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('listen to hide event when no transtion', (done) => {
|
it('listen to hide event when no transtion', (done) => {
|
||||||
@ -143,4 +140,21 @@ describe('NumberKeyboard', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('keey-alive live cycle', (done) => {
|
||||||
|
wrapper = mount(NumberKeyboardKeepAlive, {
|
||||||
|
attachToDocument: true,
|
||||||
|
propsData: {
|
||||||
|
showKeyboard: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.find('.van-number-keyboard').length).to.equal(1);
|
||||||
|
|
||||||
|
wrapper.vm.showKeyboard = false;
|
||||||
|
wrapper.vm.$nextTick(() => {
|
||||||
|
expect(wrapper.find('.van-number-keyboard').length).to.equal(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user