Skip to content

Commit 5cb824c

Browse files
committed
test: update test and snap
1 parent 77cd743 commit 5cb824c

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// LazyLoadComponent test
2+
import { mount } from '@vue/test-utils';
3+
import { expect } from 'vitest';
4+
import LazyLoadComponent from '../LazyLoadComponent.tsx';
5+
6+
test('LazyLoadComponent', async () => {
7+
const wrapper = mount(LazyLoadComponent, {
8+
props: {
9+
height: 100,
10+
width: 100,
11+
},
12+
});
13+
expect(wrapper.html()).toMatchSnapshot();
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { mount } from '@vue/test-utils';
2+
import mock from 'mockjs';
3+
import { expect, describe } from 'vitest';
4+
import LazyLoadImage from '../LazyLoadImage.tsx';
5+
describe('LazyLoadImage', async () => {
6+
const imgs = mock.mock({
7+
'list|10': [
8+
{
9+
'id|+1': 1,
10+
url: '@image(100x100, @color, @color, @word)',
11+
},
12+
],
13+
}).list;
14+
15+
it('should render correctly', async () => {
16+
const wrapper = mount(LazyLoadImage, {
17+
props: {
18+
height: 100,
19+
width: 100,
20+
src: imgs[0].url,
21+
},
22+
});
23+
expect(wrapper.html()).toMatchSnapshot();
24+
});
25+
it('should render correctly with effect', async () => {
26+
const wrapper = mount(LazyLoadImage, {
27+
props: {
28+
height: 100,
29+
width: 100,
30+
src: imgs[0].url,
31+
effect: 'blur',
32+
},
33+
});
34+
expect(wrapper.html()).toMatchSnapshot();
35+
});
36+
it('should render correctly with placeholder', async () => {
37+
const wrapper = mount(
38+
imgs.map((item: any) => (
39+
<LazyLoadImage
40+
{...item}
41+
height={100}
42+
width={100}
43+
placeholder={<div>loading...</div>}
44+
></LazyLoadImage>
45+
)),
46+
);
47+
expect(wrapper.html()).toMatchSnapshot();
48+
});
49+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`LazyLoadComponent 1`] = `""`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`LazyLoadImage > should render correctly 1`] = `"<span class=\\"lazy-load-image-background\\" style=\\"color: transparent; display: inline-block; height: 100px; width: 100px;\\"><!----></span>"`;
4+
5+
exports[`LazyLoadImage > should render correctly with effect 1`] = `"<span class=\\"lazy-load-image-background blur\\" style=\\"color: transparent; display: inline-block; height: 100px; width: 100px;\\"><!----></span>"`;
6+
7+
exports[`LazyLoadImage > should render correctly with placeholder 1`] = `""`;

0 commit comments

Comments
 (0)