test(NoticeBar): add more test cases

This commit is contained in:
chenjiahan 2020-05-30 21:30:23 +08:00 committed by neverland
parent 8ec96da204
commit 8a05cd529a
2 changed files with 62 additions and 0 deletions

View File

@ -7,3 +7,19 @@ exports[`icon slot 1`] = `
</div>
</div>Custom Right Icon</div>
`;
exports[`should not scroll when content width > wrap width 1`] = `
<div role="alert" class="van-notice-bar">
<div role="marquee" class="van-notice-bar__wrap">
<div class="van-notice-bar__content" style="transition-duration: 0s;">foo</div>
</div>
</div>
`;
exports[`should scroll when content width > wrap width 1`] = `
<div role="alert" class="van-notice-bar">
<div role="marquee" class="van-notice-bar__wrap">
<div class="van-notice-bar__content" style="transition-duration: 2s; transform: translateX(-100px);">foo</div>
</div>
</div>
`;

View File

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