From 8a05cd529ae2a6757d1662f4633af714f6a3e180 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sat, 30 May 2020 21:30:23 +0800 Subject: [PATCH] test(NoticeBar): add more test cases --- .../test/__snapshots__/index.spec.js.snap | 16 +++++++ src/notice-bar/test/index.spec.js | 46 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/src/notice-bar/test/__snapshots__/index.spec.js.snap b/src/notice-bar/test/__snapshots__/index.spec.js.snap index e765e651e..97f9e8e95 100644 --- a/src/notice-bar/test/__snapshots__/index.spec.js.snap +++ b/src/notice-bar/test/__snapshots__/index.spec.js.snap @@ -7,3 +7,19 @@ exports[`icon slot 1`] = ` Custom Right Icon `; + +exports[`should not scroll when content width > wrap width 1`] = ` + +`; + +exports[`should scroll when content width > wrap width 1`] = ` + +`; diff --git a/src/notice-bar/test/index.spec.js b/src/notice-bar/test/index.spec.js index f520ed07a..c86bebf70 100644 --- a/src/notice-bar/test/index.spec.js +++ b/src/notice-bar/test/index.spec.js @@ -48,3 +48,49 @@ test('replay event', async () => { await later(50); expect(wrapper.emitted('replay')).toBeTruthy(); }); + +test('should scroll when content width > wrap width ', async () => { + const wrapper = mount(NoticeBar, { + propsData: { + text: 'foo', + delay: 0, + }, + }); + + const wrap = wrapper.find('.van-notice-bar__wrap'); + const content = wrapper.find('.van-notice-bar__content'); + + wrap.element.getBoundingClientRect = () => ({ + width: 50, + }); + content.element.getBoundingClientRect = () => ({ + width: 100, + }); + + await later(50); + + expect(wrapper).toMatchSnapshot(); +}); + +test('should not scroll when content width > wrap width ', async () => { + const wrapper = mount(NoticeBar, { + propsData: { + text: 'foo', + delay: 0, + }, + }); + + const wrap = wrapper.find('.van-notice-bar__wrap'); + const content = wrapper.find('.van-notice-bar__content'); + + wrap.element.getBoundingClientRect = () => ({ + width: 200, + }); + content.element.getBoundingClientRect = () => ({ + width: 100, + }); + + await later(50); + + expect(wrapper).toMatchSnapshot(); +});