Skip to content

Commit 2dbb454

Browse files
committed
Add tests
1 parent 441e054 commit 2dbb454

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

test/integration/image-component/default/pages/blurry-placeholder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function Page() {
88
<Image
99
priority
1010
id="blurry-placeholder"
11-
src="/test.jpg"
11+
src="/test.ico"
1212
width="400"
1313
height="400"
1414
placeholder="blur"
@@ -19,7 +19,7 @@ export default function Page() {
1919

2020
<Image
2121
id="blurry-placeholder-with-lazy"
22-
src="/test.jpg"
22+
src="/test.bmp"
2323
width="400"
2424
height="400"
2525
placeholder="blur"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react'
2+
import Image from 'next/image'
3+
4+
const Page = () => {
5+
return (
6+
<div>
7+
<Image id="invalid-placeholder-blur" src="/test.png" placeholder="blur" />
8+
</div>
9+
)
10+
}
11+
12+
export default Page
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import Image from 'next/image'
3+
import Small from '../public/small.jpg'
4+
5+
const Page = () => {
6+
return (
7+
<div>
8+
<Image id="small-img-import" src={Small} placeholder="blur" />
9+
</div>
10+
)
11+
}
12+
13+
export default Page
439 Bytes
Loading

test/integration/image-component/default/test/index.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,27 @@ function runTests(mode) {
484484
'Failed to parse src "//assets.example.com/img.jpg" on `next/image`, protocol-relative URL (//) must be changed to an absolute URL (http:// or https://)'
485485
)
486486
})
487+
488+
it('should show invalid placeholder when blurDataUrl is missing', async () => {
489+
const browser = await webdriver(appPort, '/invalid-placeholder-blur')
490+
491+
expect(await hasRedbox(browser)).toBe(true)
492+
expect(await getRedboxHeader(browser)).toContain(
493+
`Image with src "/test.png" has "placeholder='blur'" property but is missing the "blurDataURL" property.`
494+
)
495+
})
496+
497+
it('should warn when using a very small image with placeholder=blur', async () => {
498+
const browser = await webdriver(appPort, '/small-img-import')
499+
500+
const warnings = (await browser.log('browser'))
501+
.map((log) => log.message)
502+
.join('\n')
503+
expect(await hasRedbox(browser)).toBe(false)
504+
expect(warnings).toMatch(
505+
/Image with src (.*)jpg(.*) is smaller than 40x40. Consider removing(.*)/gm
506+
)
507+
})
487508
}
488509

489510
it('should correctly ignore prose styles', async () => {

0 commit comments

Comments
 (0)