Skip to content

Commit 852371a

Browse files
committed
test: add test for URI encoding
1 parent ed573bb commit 852371a

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

test/unit/image.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,16 @@ describe('Renders simple image', () => {
4242
const sizes = wrapper.find('img').element.getAttribute('sizes')
4343
expect(sizes).toBe('(max-width: 500px) 500px, 900px')
4444
})
45+
46+
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+
}
54+
})
55+
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\\">"')
56+
})
4557
})

test/unit/picture.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ describe('Renders simple image', () => {
7070

7171
await nextTick()
7272

73-
;[['source', 'srcset', '/_ipx/f_webp&s_500x500/image.jpeg'], ['img', 'src']].forEach(([element, attribute, src]) => {
74-
const domSrc = wrapper.find(element).element.getAttribute(attribute)
75-
expect(domSrc).toContain(src || newSource)
76-
})
73+
;[['source', 'srcset', '/_ipx/f_webp&s_500x500/image.jpeg'], ['img', 'src']].forEach(([element, attribute, src]) => {
74+
const domSrc = wrapper.find(element).element.getAttribute(attribute)
75+
expect(domSrc).toContain(src || newSource)
76+
})
7777
})
7878

7979
it('sizes', () => {
@@ -89,4 +89,21 @@ describe('Renders simple image', () => {
8989
})
9090
expect(wrapper.html()).toMatchInlineSnapshot('"<picture><img data-nuxt-pic=\\"\\" src=\\"/image.svg\\"></picture>"')
9191
})
92+
93+
it('encodes characters', () => {
94+
const img = mount(NuxtPicture, {
95+
propsData: {
96+
loading: 'lazy',
97+
width: 200,
98+
height: 200,
99+
sizes: '200,500:500,900:900',
100+
src: '/汉字.png'
101+
}
102+
})
103+
expect(img.html()).toMatchInlineSnapshot(`
104+
"<picture>
105+
<source type=\\"image/webp\\" sizes=\\"(max-width: 500px) 500px, 900px\\" srcset=\\"/_ipx/f_webp&s_500x500/%E6%B1%89%E5%AD%97.png 500w, /_ipx/f_webp&s_900x900/%E6%B1%89%E5%AD%97.png 900w\\"><img width=\\"200\\" height=\\"200\\" data-nuxt-pic=\\"\\" src=\\"/_ipx/f_png&s_900x900/%E6%B1%89%E5%AD%97.png\\" sizes=\\"(max-width: 500px) 500px, 900px\\" srcset=\\"/_ipx/f_png&s_500x500/%E6%B1%89%E5%AD%97.png 500w, /_ipx/f_png&s_900x900/%E6%B1%89%E5%AD%97.png 900w\\">
106+
</picture>"
107+
`)
108+
})
92109
})

0 commit comments

Comments
 (0)