Fix: 修复toast关闭时未移除Dom节点,以及补上单元测试 (#19)

* 文档页样式和打包配置优化

* upload unit test

* intanbul ignore src/index

* unit test

* utils dom unit test

* fix: toast not remove

* remove dom unit test

* remove toast clear unit test

* remove toast import vue
This commit is contained in:
张敏 2017-04-26 15:49:44 +08:00 committed by GitHub
parent 639d3a65c5
commit b4544ef1dc
3 changed files with 71 additions and 10 deletions

View File

@ -14,6 +14,7 @@ const getInstance = () => {
}; };
const removeDom = event => { const removeDom = event => {
/* istanbul ignore else */
if (event.target.parentNode) { if (event.target.parentNode) {
event.target.parentNode.removeChild(event.target); event.target.parentNode.removeChild(event.target);
} }
@ -69,6 +70,7 @@ Toast.fail = (options) => {
}; };
Toast.clear = () => { Toast.clear = () => {
/* istanbul ignore else */
if (instance) instance.clear(); if (instance) instance.clear();
}; };

View File

@ -51,6 +51,9 @@
} }
} }
.van-toast-fade-enter, .van-toast-fade-leave-active { .van-toast-fade-enter-active, .van-toast-fade-leave-active {
transition: opacity .2s;
}
.van-toast-fade-enter, .van-toast-fade-leave-to {
opacity: 0; opacity: 0;
} }

View File

@ -8,32 +8,88 @@ describe('Toast', () => {
el.parentNode.removeChild(el); el.parentNode.removeChild(el);
} }
Toast.clear(); Toast.clear();
if (el.__vue__) {
el.__vue__.$destroy();
}
}); });
it('create a toast', () => { it('create a empty toast', () => {
Toast('我是提示文案,建议不超过十五字~'); const toast = Toast();
expect(document.querySelector('.van-toast-wrapper')).to.exist; expect(document.querySelector('.van-toast-wrapper')).to.exist;
}); });
it('create a toast', (done) => {
const toast = Toast('toast');
expect(document.querySelector('.van-toast-wrapper')).to.exist;
expect(toast.message).to.equal('toast');
expect(toast.type).to.equal('text');
setTimeout(() => {
expect(typeof toast.timer).to.equal('number');
done();
}, 500);
});
it('create a loading toast', () => { it('create a loading toast', () => {
Toast.loading(); const toast = Toast.loading();
expect(document.querySelector('.van-toast-wrapper')).to.exist; expect(document.querySelector('.van-toast-wrapper')).to.exist;
expect(toast.type).to.equal('loading');
});
it('create a options loading toast', () => {
const toast = Toast.loading({
message: 'toast'
});
expect(document.querySelector('.van-toast-wrapper')).to.exist;
expect(toast.message).to.equal('toast');
expect(toast.type).to.equal('loading');
}); });
it('create a success toast', () => { it('create a success toast', () => {
Toast.success('success'); const toast = Toast.success('success');
expect(document.querySelector('.van-toast-wrapper')).to.exist; expect(document.querySelector('.van-toast-wrapper')).to.exist;
expect(toast.type).to.equal('success');
}); });
it('create a fali toast', () => { it('create a options success toast', () => {
Toast.fail('fail'); const toast = Toast.success({
message: 'toast'
});
expect(document.querySelector('.van-toast-wrapper')).to.exist; expect(document.querySelector('.van-toast-wrapper')).to.exist;
expect(toast.message).to.equal('toast');
expect(toast.type).to.equal('success');
});
it('create a fail toast', () => {
const toast = Toast.fail('fail');
expect(document.querySelector('.van-toast-wrapper')).to.exist;
expect(toast.type).to.equal('fail');
});
it('create a options fail toast', () => {
const toast = Toast.fail({
message: 'toast'
});
expect(document.querySelector('.van-toast-wrapper')).to.exist;
expect(toast.message).to.equal('toast');
expect(toast.type).to.equal('fail');
});
it('create a forbidClick toast', (done) => {
Toast({
message: 'test',
forbidClick: true
});
expect(document.querySelector('.van-toast-wrapper')).to.exist;
setTimeout(() => {
expect(document.querySelector('.van-toast__overlay')).to.exist;
done();
}, 500);
}); });
}); });