Skip to content

Commit

Permalink
Throw instead of log error
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Oct 22, 2020
1 parent 39fb88e commit 7a1bd3d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions packages/next/client/image.tsx
Expand Up @@ -157,7 +157,7 @@ export default function Image({
if (priority && lazy) {
if (process.env.NODE_ENV !== 'production') {
throw new Error(
`Image with src ${src} has both priority and lazy properties. Only one should be used.`
`Image with src "${src}" has both "priority" and "lazy" properties. Only one should be used.`
)
}
}
Expand Down Expand Up @@ -254,14 +254,15 @@ export default function Image({
if (priority) {
// <Image src="i.png" unsized priority />
console.warn(
`Image with src ${src} has both priority and unsized attributes. Only one should be used.`
`Image with src "${src}" has both "priority" and "unsized" properties. Only one should be used.`
)
}
}
} else {
// <Image src="i.png" />
if (process.env.NODE_ENV !== 'production') {
console.error(
`Image with src ${src} must use width and height attributes or unsized attribute.`
throw new Error(
`Image with src "${src}" must use "width" and "height" properties or "unsized" property.`
)
}
}
Expand Down
Expand Up @@ -45,14 +45,14 @@ describe('TypeScript Image Component', () => {
const html = await renderViaHTTP(appPort, '/valid', {})
expect(html).toMatch(/This is valid usage of the Image component/)
expect(output).not.toMatch(
/must use width and height attributes or unsized attribute/
/must use "width" and "height" properties or "unsized" property/
)
})

it('should print error when invalid Image usage', async () => {
await renderViaHTTP(appPort, '/invalid', {})
expect(output).toMatch(
/must use width and height attributes or unsized attribute/
/must use "width" and "height" properties or "unsized" property/
)
})
})
Expand Down

0 comments on commit 7a1bd3d

Please sign in to comment.