From b4544ef1dcb7e39dcc07448bba5654e927fb7829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=95=8F?= Date: Wed, 26 Apr 2017 15:49:44 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BF=AE=E5=A4=8Dtoast=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=97=B6=E6=9C=AA=E7=A7=BB=E9=99=A4Dom=E8=8A=82?= =?UTF-8?q?=E7=82=B9=EF=BC=8C=E4=BB=A5=E5=8F=8A=E8=A1=A5=E4=B8=8A=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=20(#19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 文档页样式和打包配置优化 * 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 --- packages/toast/src/toast.js | 2 + packages/vant-css/src/toast.css | 5 ++- test/unit/specs/toast.spec.js | 74 +++++++++++++++++++++++++++++---- 3 files changed, 71 insertions(+), 10 deletions(-) diff --git a/packages/toast/src/toast.js b/packages/toast/src/toast.js index d5e1d39d8..3833f9894 100644 --- a/packages/toast/src/toast.js +++ b/packages/toast/src/toast.js @@ -14,6 +14,7 @@ const getInstance = () => { }; const removeDom = event => { + /* istanbul ignore else */ if (event.target.parentNode) { event.target.parentNode.removeChild(event.target); } @@ -69,6 +70,7 @@ Toast.fail = (options) => { }; Toast.clear = () => { + /* istanbul ignore else */ if (instance) instance.clear(); }; diff --git a/packages/vant-css/src/toast.css b/packages/vant-css/src/toast.css index fc27bea7c..95e00469e 100644 --- a/packages/vant-css/src/toast.css +++ b/packages/vant-css/src/toast.css @@ -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; } diff --git a/test/unit/specs/toast.spec.js b/test/unit/specs/toast.spec.js index ace7130cd..6078dc5b7 100644 --- a/test/unit/specs/toast.spec.js +++ b/test/unit/specs/toast.spec.js @@ -8,32 +8,88 @@ describe('Toast', () => { el.parentNode.removeChild(el); } Toast.clear(); - if (el.__vue__) { - el.__vue__.$destroy(); - } }); - it('create a toast', () => { - Toast('我是提示文案,建议不超过十五字~'); + it('create a empty toast', () => { + const toast = Toast(); + + 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', () => { - Toast.loading(); + const toast = Toast.loading(); 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', () => { - Toast.success('success'); + const toast = Toast.success('success'); expect(document.querySelector('.van-toast-wrapper')).to.exist; + expect(toast.type).to.equal('success'); }); - it('create a fali toast', () => { - Toast.fail('fail'); + it('create a options success toast', () => { + const toast = Toast.success({ + message: 'toast' + }); 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); }); });