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); }); });