Files
vant/src/notice-bar/test/index.spec.tsx
T
neverlandandGitHub 1381070a12 chore: prefer named exports (#8315)
* chore: prefer named exports

* chore: fix import
2021-03-09 15:39:26 +08:00

94 lines
2.1 KiB
TypeScript

import { NoticeBar } from '..';
import { mount, later } from '../../../test';
test('should emit close event when close icon is clicked', () => {
const wrapper = mount(NoticeBar, {
props: {
mode: 'closeable',
},
});
const close = wrapper.find('.van-notice-bar__right-icon');
close.trigger('click');
expect(wrapper.emitted<[Event]>('close')![0][0]).toBeTruthy();
});
test('should render icon slot correct', () => {
const wrapper = mount({
render: () => (
<NoticeBar
v-slots={{
'left-icon': () => 'Custom Left Icon',
'right-icon': () => 'Custom Right Icon',
}}
>
Content
</NoticeBar>
),
});
expect(wrapper.html()).toMatchSnapshot();
});
test('should emit replay event after replay', async () => {
const wrapper = mount(NoticeBar, {
props: {
text: 'foo',
},
});
wrapper.find('.van-notice-bar__content').trigger('transitionend');
await later(80);
expect(wrapper.emitted('replay')).toBeTruthy();
});
test('should start scrolling when content width > wrap width ', async () => {
const wrapper = mount(NoticeBar, {
props: {
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,
} as DOMRect);
content.element.getBoundingClientRect = () =>
({
width: 100,
} as DOMRect);
await later(50);
expect(wrapper.html()).toMatchSnapshot();
});
test('should not start scrolling when content width > wrap width ', async () => {
const wrapper = mount(NoticeBar, {
props: {
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,
} as DOMRect);
content.element.getBoundingClientRect = () =>
({
width: 100,
} as DOMRect);
await later(50);
expect(wrapper.html()).toMatchSnapshot();
});