Skip to content

Commit 5c21f4c

Browse files
committed
test: extract mountImage helper
1 parent 7e187e5 commit 5c21f4c

1 file changed

Lines changed: 18 additions & 22 deletions

File tree

test/unit/image.test.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @vitest-environment nuxt
22

33
import { beforeEach, describe, it, expect } from 'vitest'
4-
import { VueWrapper, mount } from '@vue/test-utils'
4+
import { ComponentMountingOptions, VueWrapper, mount } from '@vue/test-utils'
55

66
import { NuxtImg } from '#components'
77

@@ -10,13 +10,11 @@ describe('Renders simple image', () => {
1010
const src = '/image.png'
1111

1212
beforeEach(() => {
13-
wrapper = mount(NuxtImg, {
14-
propsData: {
15-
width: 200,
16-
height: 200,
17-
sizes: '200,500:500,900:900',
18-
src
19-
}
13+
wrapper = mountImage({
14+
width: 200,
15+
height: 200,
16+
sizes: '200,500:500,900:900',
17+
src
2018
})
2119
})
2220

@@ -44,26 +42,24 @@ describe('Renders simple image', () => {
4442
})
4543

4644
it('encodes characters', () => {
47-
const img = mount(NuxtImg, {
48-
propsData: {
49-
width: 200,
50-
height: 200,
51-
sizes: '200,500:500,900:900',
52-
src: '/汉字.png'
53-
}
45+
const img = mountImage({
46+
width: 200,
47+
height: 200,
48+
sizes: '200,500:500,900:900',
49+
src: '/汉字.png'
5450
})
5551
expect(img.html()).toMatchInlineSnapshot('"<img src=\\"/_ipx/s_900x900/%E6%B1%89%E5%AD%97.png\\" width=\\"200\\" height=\\"200\\" data-nuxt-img=\\"\\" sizes=\\"(max-width: 500px) 500px, 900px\\" srcset=\\"/_ipx/s_500x500/%E6%B1%89%E5%AD%97.png 500w, /_ipx/s_900x900/%E6%B1%89%E5%AD%97.png 900w\\">"')
5652
})
5753

5854
it('correctly sets crop', () => {
59-
const img = mount(NuxtImg, {
60-
propsData: {
61-
src: '/image.png',
62-
width: 1000,
63-
height: 2000,
64-
sizes: 'xs:100vw sm:100vw md:300px lg:350px xl:350px 2xl:350px'
65-
}
55+
const img = mountImage({
56+
src: '/image.png',
57+
width: 1000,
58+
height: 2000,
59+
sizes: 'xs:100vw sm:100vw md:300px lg:350px xl:350px 2xl:350px'
6660
})
6761
expect(img.html()).toMatchInlineSnapshot('"<img src=\\"/_ipx/s_350x700/image.png\\" width=\\"1000\\" height=\\"2000\\" data-nuxt-img=\\"\\" sizes=\\"(max-width: 320px) 100vw, (max-width: 640px) 100vw, (max-width: 768px) 300px, (max-width: 1024px) 350px, (max-width: 1280px) 350px, 350px\\" srcset=\\"/_ipx/s_320x640/image.png 320w, /_ipx/s_640x1280/image.png 640w, /_ipx/s_300x600/image.png 300w, /_ipx/s_350x700/image.png 350w, /_ipx/s_350x700/image.png 350w, /_ipx/s_350x700/image.png 350w\\">"')
6862
})
6963
})
64+
65+
const mountImage = (props: ComponentMountingOptions<typeof NuxtImg>['props']) => mount(NuxtImg, { props })

0 commit comments

Comments
 (0)