From 561821d03acd295bab4330ab5501c1feb0933c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Mon, 28 Aug 2017 14:40:00 +0800 Subject: [PATCH] NoticeBar: improve test coverage --- packages/notice-bar/index.vue | 2 +- test/unit/components/notice-bar.vue | 16 ++++++++++++++++ test/unit/index.js | 2 +- test/unit/specs/notice-bar.spec.js | 11 +++++------ 4 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 test/unit/components/notice-bar.vue diff --git a/packages/notice-bar/index.vue b/packages/notice-bar/index.vue index 3540c4833..4060dccc6 100644 --- a/packages/notice-bar/index.vue +++ b/packages/notice-bar/index.vue @@ -70,7 +70,7 @@ export default { const wrapWidth = this.$refs.contentWrap.getBoundingClientRect().width; if (this.scrollable && offsetWidth > wrapWidth) { this.offsetWidth = offsetWidth; - this.duration = Math.ceil((offsetWidth + wrapWidth) / this.speed); + this.duration = (offsetWidth + wrapWidth) / this.speed; } }, diff --git a/test/unit/components/notice-bar.vue b/test/unit/components/notice-bar.vue new file mode 100644 index 000000000..7eed57545 --- /dev/null +++ b/test/unit/components/notice-bar.vue @@ -0,0 +1,16 @@ + + + + diff --git a/test/unit/index.js b/test/unit/index.js index 9f20bac30..cac038bbe 100644 --- a/test/unit/index.js +++ b/test/unit/index.js @@ -13,4 +13,4 @@ if (process.env.TEST_FILE) { }); } else { testsReq.keys().forEach(testsReq); -} \ No newline at end of file +} diff --git a/test/unit/specs/notice-bar.spec.js b/test/unit/specs/notice-bar.spec.js index f85d09b36..87c796e44 100644 --- a/test/unit/specs/notice-bar.spec.js +++ b/test/unit/specs/notice-bar.spec.js @@ -1,4 +1,4 @@ -import NoticeBar from 'packages/notice-bar'; +import NoticeBar from '../components/notice-bar'; import { mount } from 'avoriaz'; describe('NoticeBar', () => { @@ -13,7 +13,7 @@ describe('NoticeBar', () => { attachToDocument: true }); - expect(wrapper.hasClass('van-notice-bar')).to.be.true; + expect(wrapper.find('.van-notice-bar').length).to.equal(1); }); it('mode closeable', () => { @@ -45,18 +45,17 @@ describe('NoticeBar', () => { it('notice-bar transitionend', (done) => { wrapper = mount(NoticeBar, { propsData: { - text: '足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。', - speed: 10000, + text: '足协杯战线连续第2年上演广州德比战', + speed: 1000, delay: 0 }, attachToDocument: true }); const content = wrapper.find('.van-notice-bar__content')[0]; - setTimeout(() => { expect(content.hasStyle('transition-delay', '0s')).to.be.true; done(); - }, 1500); + }, 500); }); });