Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
unsized
property to Image component (#18059)
- Loading branch information
Showing
8 changed files
with
185 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
images: { | ||
domains: ['via.placeholder.com'], | ||
}, | ||
} |
17 changes: 17 additions & 0 deletions
17
test/integration/image-component/typescript/pages/invalid.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react' | ||
import Image from 'next/image' | ||
|
||
const Invalid = () => { | ||
return ( | ||
<div> | ||
<h1>Hello World</h1> | ||
<Image | ||
id="no-width-or-height" | ||
src="https://via.placeholder.com/500" | ||
></Image> | ||
<p id="stubtext">This is the invalid usage</p> | ||
</div> | ||
) | ||
} | ||
|
||
export default Invalid |
24 changes: 24 additions & 0 deletions
24
test/integration/image-component/typescript/pages/valid.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react' | ||
import Image from 'next/image' | ||
|
||
const Page = () => { | ||
return ( | ||
<div> | ||
<p>Hello World</p> | ||
<Image | ||
id="with-and-height" | ||
src="https://via.placeholder.com/500" | ||
width={500} | ||
height={500} | ||
></Image> | ||
<Image | ||
id="unsized-image" | ||
src="https://via.placeholder.com/100" | ||
unsized | ||
></Image> | ||
<p id="stubtext">This is valid usage of the Image component</p> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
59 changes: 59 additions & 0 deletions
59
test/integration/image-component/typescript/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import { | ||
renderViaHTTP, | ||
findPort, | ||
launchApp, | ||
nextBuild, | ||
killApp, | ||
} from 'next-test-utils' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
const appDir = join(__dirname, '..') | ||
let appPort | ||
let app | ||
let output | ||
|
||
const handleOutput = (msg) => { | ||
output += msg | ||
} | ||
|
||
describe('TypeScript Image Component', () => { | ||
describe('next build', () => { | ||
it('should fail to build invalid usage of the Image component', async () => { | ||
const { stderr, code } = await nextBuild(appDir, [], { stderr: true }) | ||
expect(stderr).toMatch(/Failed to compile/) | ||
expect(stderr).toMatch(/is not assignable to type/) | ||
expect(code).toBe(1) | ||
}) | ||
}) | ||
|
||
describe('next dev', () => { | ||
beforeAll(async () => { | ||
output = '' | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort, { | ||
onStdout: handleOutput, | ||
onStderr: handleOutput, | ||
}) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
it('should render the valid Image usage and not print error', async () => { | ||
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/ | ||
) | ||
}) | ||
|
||
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/ | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"jsx": "preserve", | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true | ||
}, | ||
"exclude": ["node_modules"], | ||
"include": ["next-env.d.ts", "components", "pages"] | ||
} |