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 NumberKeyboardKeepAlive from '../components/number-keyboard';
|
||||
import { mount } from 'avoriaz';
|
||||
import { triggerTouch } from '../utils';
|
||||
|
||||
function mockKeyDown(wrapper, keyIndex) {
|
||||
const customEvent = document.createEvent('CustomEvent');
|
||||
customEvent.initCustomEvent('touchstart', true, true, {});
|
||||
Object.defineProperty(customEvent, 'target', {
|
||||
value: {
|
||||
dataset: {
|
||||
key: keyIndex
|
||||
}
|
||||
}
|
||||
});
|
||||
wrapper.element.dataset.key = keyIndex;
|
||||
wrapper.element.dispatchEvent(customEvent);
|
||||
}
|
||||
|
||||
@ -82,11 +77,12 @@ describe('NumberKeyboard', () => {
|
||||
const show = sinon.spy();
|
||||
wrapper.vm.$on('show', show);
|
||||
wrapper.vm.show = true;
|
||||
wrapper.trigger('animationend');
|
||||
|
||||
setTimeout(() => {
|
||||
expect(show.calledOnce).to.be.true;
|
||||
done();
|
||||
}, 800);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('listen to show event when no transtion', (done) => {
|
||||
@ -118,11 +114,12 @@ describe('NumberKeyboard', () => {
|
||||
const hide = sinon.spy();
|
||||
wrapper.vm.$on('hide', hide);
|
||||
wrapper.vm.show = false;
|
||||
wrapper.trigger('animationend');
|
||||
|
||||
setTimeout(() => {
|
||||
expect(hide.calledOnce).to.be.true;
|
||||
done();
|
||||
}, 800);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('listen to hide event when no transtion', (done) => {
|
||||
@ -143,4 +140,21 @@ describe('NumberKeyboard', () => {
|
||||
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