Unverified Commit 306c467c authored by Delba de Oliveira's avatar Delba de Oliveira Committed by GitHub

Update Jest examples and docs (#31633)

Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
Co-authored-by: 's avatarLee Robinson <me@leerob.io>
Co-authored-by: 's avatarstefanprobst <stefan.probst@univie.ac.at>
Co-authored-by: 's avatarRich Haines <hello@richardhaines.dev>
parent b01a6ba6
---
description: Learn how to set up Next.js with three commonly used testing tools — Cypress, Jest, and React Testing Library.
description: Learn how to set up Next.js with three commonly used testing tools — Cypress, Playwright, Jest, and React Testing Library.
---
# Testing
......@@ -243,31 +243,69 @@ You can learn more about Playwright and Continuous Integration from these resour
## Jest and React Testing Library
Jest and React Testing Library are frequently used together for **Unit Testing**.
Jest and React Testing Library are frequently used together for **Unit Testing**. There are three ways you can start using Jest within your Next.js application:
1. Using one of our [quickstart examples](https://nextjs.org/docs/testing#quickstart-2)
2. With the [Next.js Rust Compiler](https://nextjs.org/docs/testing#setting-up-jest-with-the-rust-compiler)
3. With [Babel](https://nextjs.org/docs/testing#setting-up-jest-with-babel)
The following sections will go through how you can set up Jest with each of these options:
### Quickstart
You can use `create-next-app` with the [with-jest example](https://github.com/vercel/next.js/tree/canary/examples/with-jest) to quickly get started with Jest and React Testing Library:
You can use `create-next-app` with the [with-jest](https://github.com/vercel/next.js/tree/canary/examples/with-jest) example to quickly get started with Jest and React Testing Library:
```bash
npx create-next-app@latest --example with-jest with-jest-app
```
### Manual setup
### Setting up Jest (with the Rust Compiler)
Since the release of [Next.js 12](https://nextjs.org/blog/next-12), Next.js now has built-in configuration for Jest.
To manually set up Jest and React Testing Library, install `jest` , `@testing-library/react`, `@testing-library/jest-dom` as well as some supporting packages:
To set up Jest, install `jest` , `@testing-library/react`, `@testing-library/jest-dom` and `react-test-renderer`:
```bash
npm install --save-dev jest babel-jest @testing-library/react @testing-library/jest-dom identity-obj-proxy react-test-renderer
npm install --save-dev jest @testing-library/react @testing-library/jest-dom react-test-renderer
```
**Configuring Jest**
Create a `jest.config.js` file in your project's root directory and add the following configuration options:
Create a `jest.config.js` file in your project's root directory and add the following:
```jsx
// jest.config.js
const nextJest = require('next/jest')
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})
// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
}
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
```
Under the hood, `next/jest` is automatically configuring Jest for you, including:
- Setting up `transform` using [SWC](https://nextjs.org/docs/advanced-features/compiler)
- Auto mocking stylesheets (`.css`, `.module.css`, and their scss variants) and image imports
- Loading `.env` (and all variants) into `process.env`
- Ignoring `node_modules` from test resolving and transforms
- Ignoring `.next` from test resolving
- Loading `next.config.js` for flags that enable SWC transforms
### Setting up Jest (with Babel)
If you opt-out of the [Rust Compiler](https://nextjs.org/docs/advanced-features/compiler), you will need to manually configure Jest and install `babel-jest` and `identity-obj-proxy` in addition to the packages above.
Here are the recommended options to configure Jest for Next.js:
```jsx
// jest.config.js
module.exports = {
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
......@@ -275,23 +313,26 @@ module.exports = {
'!**/node_modules/**',
],
moduleNameMapper: {
/* Handle CSS imports (with CSS modules)
https://jestjs.io/docs/webpack#mocking-css-modules */
// Handle CSS imports (with CSS modules)
// https://jestjs.io/docs/webpack#mocking-css-modules
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
// Handle CSS imports (without CSS modules)
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js',
/* Handle image imports
https://jestjs.io/docs/webpack#handling-static-assets */
'^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$':
'<rootDir>/__mocks__/fileMock.js',
// Handle image imports
// https://jestjs.io/docs/webpack#handling-static-assets
'^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$': `<rootDir>/__mocks__/fileMock.js`,
// Handle module aliases
'^@/components/(.*)$': '<rootDir>/components/$1',
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
testEnvironment: 'jsdom',
transform: {
/* Use babel-jest to transpile tests with the next/babel preset
https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object */
// Use babel-jest to transpile tests with the next/babel preset
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
},
transformIgnorePatterns: [
......@@ -301,41 +342,37 @@ module.exports = {
}
```
You can learn more about each option above in the [Jest docs](https://jestjs.io/docs/configuration).
You can learn more about each configuration option in the [Jest docs](https://jestjs.io/docs/configuration).
**Handling stylesheets and image imports**
These files aren't useful in tests but importing them may cause errors, so we will need to mock them. Create the mock files we referenced in the configuration above - `fileMock.js` and `styleMock.js` - inside a `__mocks__` directory:
Styleheets and images aren't used in the tests but importing them may cause errors, so they will need to be mocked. Create the mock files referenced in the configuration above - `fileMock.js` and `styleMock.js` - inside a `__mocks__` directory:
```json
```js
// __mocks__/fileMock.js
(module.exports = "test-file-stub")
module.exports = 'test-file-stub'
```
```json
```js
// __mocks__/styleMock.js
module.exports = {};
module.exports = {}
```
If you're running into the issue `"Failed to parse src "test-file-stub" on 'next/image'"`, add a '/' to your fileMock.
```json
```js
// __mocks__/fileMock.js
(module.exports = "/test-file-stub")
module.exports = '/test-file-stub'
```
For more information on handling static assets, please refer to the [Jest Docs](https://jestjs.io/docs/webpack#handling-static-assets).
**Extend Jest with custom matchers**
**Optional: Extend Jest with custom matchers**
`@testing-library/jest-dom` includes a set of convenient [custom matchers](https://github.com/testing-library/jest-dom#custom-matchers) such as `.toBeInTheDocument()` making it easier to write tests. You can import the custom matchers for every test by adding the following option to the Jest configuration file:
```json
```js
// jest.config.js
setupFilesAfterEnv: ['<rootDir>/jest.setup.js']
```
......@@ -343,13 +380,12 @@ Then, inside `jest.setup.js`, add the following import:
```jsx
// jest.setup.js
import '@testing-library/jest-dom/extend-expect'
```
If you need to add more setup options before each test, it's common to add them to the `jest.setup.js` file above.
**Absolute Imports and Module Path Aliases**
**Optional: Absolute Imports and Module Path Aliases**
If your project is using [Module Path Aliases](https://nextjs.org/docs/advanced-features/module-path-aliases), you will need to configure Jest to resolve the imports by matching the paths option in the `jsconfig.json` file with the `moduleNameMapper` option in the `jest.config.js` file. For example:
......@@ -372,6 +408,8 @@ moduleNameMapper: {
}
```
### Creating your tests:
**Add a test script to package.json**
Add the Jest executable in watch mode to the `package.json` scripts:
......
{
"root": true,
"extends": ["next/core-web-vitals"],
"plugins": ["testing-library"],
"overrides": [
// Only uses Testing Library lint rules in test files
{
"files": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[jt]s?(x)"
],
"extends": ["plugin:testing-library/react"]
}
]
}
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
# vercel
.vercel
# Next.js + Jest
This example shows how to configure Jest to work with Next.js and Babel. Since the release of Next.js 12, Next.js has in-built configuration for Jest with SWC. See the [with-jest](https://github.com/vercel/next.js/tree/canary/examples/with-jest) example for the latest implementation.
This includes Next.js' built-in support for Global CSS, CSS Modules, and TypeScript!
## How to Use
Quickly get started using [Create Next App](https://github.com/vercel/next.js/tree/canary/packages/create-next-app#readme)!
In your terminal, run the following command:
```bash
npx create-next-app --example with-jest with-jest-app
# or
yarn create next-app --example with-jest with-jest-app
```
## Run Jest Tests
```bash
npm test
```
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders homepage unchanged 1`] = `
<div
className="container"
>
<main>
<h1
className="title"
>
Welcome to
<a
href="https://nextjs.org"
>
Next.js!
</a>
</h1>
<p
className="description"
>
Get started by editing
<code>
pages/index.js
</code>
</p>
<div
className="grid"
>
<a
className="card"
href="https://nextjs.org/docs"
>
<h3>
Documentation →
</h3>
<p>
Find in-depth information about Next.js features and API.
</p>
</a>
<a
className="card"
href="https://nextjs.org/learn"
>
<h3>
Learn →
</h3>
<p>
Learn about Next.js in an interactive course with quizzes!
</p>
</a>
<a
className="card"
href="https://github.com/vercel/next.js/tree/master/examples"
>
<h3>
Examples →
</h3>
<p>
Discover and deploy boilerplate example Next.js projects.
</p>
</a>
<a
className="card"
href="https://vercel.com/new"
>
<h3>
Deploy →
</h3>
<p>
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
</div>
</main>
<footer
className="footer"
>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
rel="noopener noreferrer"
target="_blank"
>
Powered by
<span
className="logo"
>
<span
style={
Object {
"background": "none",
"border": 0,
"boxSizing": "border-box",
"display": "inline-block",
"height": "initial",
"margin": 0,
"maxWidth": "100%",
"opacity": 1,
"overflow": "hidden",
"padding": 0,
"position": "relative",
"width": "initial",
}
}
>
<span
style={
Object {
"background": "none",
"border": 0,
"boxSizing": "border-box",
"display": "block",
"height": "initial",
"margin": 0,
"maxWidth": "100%",
"opacity": 1,
"padding": 0,
"width": "initial",
}
}
>
<img
alt=""
aria-hidden={true}
src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNzIiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmVyc2lvbj0iMS4xIi8+"
style={
Object {
"background": "none",
"border": 0,
"display": "block",
"height": "initial",
"margin": 0,
"maxWidth": "100%",
"opacity": 1,
"padding": 0,
"width": "initial",
}
}
/>
</span>
<img
alt="Vercel Logo"
data-nimg="intrinsic"
decoding="async"
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
style={
Object {
"border": "none",
"bottom": 0,
"boxSizing": "border-box",
"display": "block",
"height": 0,
"left": 0,
"margin": "auto",
"maxHeight": "100%",
"maxWidth": "100%",
"minHeight": "100%",
"minWidth": "100%",
"objectFit": undefined,
"objectPosition": undefined,
"padding": 0,
"position": "absolute",
"right": 0,
"top": 0,
"width": 0,
}
}
/>
<noscript>
<img
alt="Vercel Logo"
data-nimg="intrinsic"
decoding="async"
loading="lazy"
src="/_next/image?url=%2Fvercel.svg&w=256&q=75"
srcSet="/_next/image?url=%2Fvercel.svg&w=96&q=75 1x, /_next/image?url=%2Fvercel.svg&w=256&q=75 2x"
style={
Object {
"border": "none",
"bottom": 0,
"boxSizing": "border-box",
"display": "block",
"height": 0,
"left": 0,
"margin": "auto",
"maxHeight": "100%",
"maxWidth": "100%",
"minHeight": "100%",
"minWidth": "100%",
"objectFit": undefined,
"objectPosition": undefined,
"padding": 0,
"position": "absolute",
"right": 0,
"top": 0,
"width": 0,
}
}
/>
</noscript>
</span>
</span>
</a>
</footer>
</div>
`;
/**
* @jest-environment jsdom
*/
import React from 'react'
import { render, screen } from '@testing-library/react'
import Home from '../pages/index'
describe('Home', () => {
it('renders a heading', () => {
render(<Home />)
const heading = screen.getByRole('heading', {
name: /welcome to next\.js!/i,
})
expect(heading).toBeInTheDocument()
})
})
import React from 'react'
import renderer from 'react-test-renderer'
import Index from '../pages/index'
it('renders homepage unchanged', () => {
const tree = renderer.create(<Index />).toJSON()
expect(tree).toMatchSnapshot()
})
// You can learn more about each option below in the Jest docs: https://jestjs.io/docs/configuration.
module.exports = {
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
],
moduleNameMapper: {
// Handle CSS imports (with CSS modules)
// https://jestjs.io/docs/webpack#mocking-css-modules
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
// Handle CSS imports (without CSS modules)
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js',
// Handle image imports
// https://jestjs.io/docs/webpack#handling-static-assets
'^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$': `<rootDir>/__mocks__/fileMock.js`,
// Handle module aliases
'^@/components/(.*)$': '<rootDir>/components/$1',
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
transform: {
// Use babel-jest to transpile tests with the next/babel preset
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
},
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
],
}
// Optional: configure or set up a testing framework before each test.
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js`
// Used for __tests__/testing-library.js
// Learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect'
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/components/*": ["components/*"]
}
}
}
{
"private": true,
"scripts": {
"dev": "next dev",
"lint": "next lint",
"build": "next build",
"start": "next start",
"test": "jest --watch",
"test:ci": "jest --ci"
},
"dependencies": {
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@testing-library/jest-dom": "5.14.1",
"@testing-library/react": "12.0.0",
"@testing-library/user-event": "13.2.1",
"babel-jest": "27.0.6",
"eslint": "7.32.0",
"eslint-config-next": "latest",
"eslint-plugin-testing-library": "4.11.0",
"identity-obj-proxy": "3.0.0",
"jest": "27.0.6",
"react-test-renderer": "17.0.2"
}
}
import '../styles/global.css'
// This default export is required in a new `pages/_app.js` file.
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
import Head from 'next/head'
import styles from './index.module.css'
import Image from 'next/image'
const Home = () => (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>
<p className={styles.description}>
Get started by editing <code>pages/index.js</code>
</p>
<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h3>Documentation &rarr;</h3>
<p>Find in-depth information about Next.js features and API.</p>
</a>
<a href="https://nextjs.org/learn" className={styles.card}>
<h3>Learn &rarr;</h3>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>
<a
href="https://github.com/vercel/next.js/tree/master/examples"
className={styles.card}
>
<h3>Examples &rarr;</h3>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>
<a href="https://vercel.com/new" className={styles.card}>
<h3>Deploy &rarr;</h3>
<p>Instantly deploy your Next.js site to a public URL with Vercel.</p>
</a>
</div>
</main>
<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<span className={styles.logo}>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
</footer>
</div>
)
export default Home
.container {
min-height: 100vh;
padding: 0 0.5rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.title a {
color: #0070f3;
text-decoration: none;
}
.title a:hover,
.title a:focus,
.title a:active {
text-decoration: underline;
}
.title {
margin: 0;
line-height: 1.15;
font-size: 4rem;
}
.title,
.description {
text-align: center;
}
.description {
line-height: 1.5;
font-size: 1.5rem;
}
.grid {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
max-width: 800px;
margin-top: 3rem;
}
.card {
margin: 1rem;
flex-basis: 45%;
padding: 1.5rem;
text-align: left;
color: inherit;
text-decoration: none;
border: 1px solid #eaeaea;
border-radius: 10px;
transition: color 0.15s ease, border-color 0.15s ease;
}
.card:hover,
.card:focus,
.card:active {
color: #0070f3;
border-color: #0070f3;
}
.card h3 {
margin: 0 0 1rem 0;
font-size: 1.5rem;
}
.card p {
margin: 0;
font-size: 1.25rem;
line-height: 1.5;
}
.logo {
height: 1em;
margin-left: 0.5rem;
}
@media (max-width: 600px) {
.grid {
width: 100%;
flex-direction: column;
}
}
<svg width="283" height="64" viewBox="0 0 283 64" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/>
</svg>
\ No newline at end of file
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
* {
box-sizing: border-box;
}
main {
padding: 5rem 0;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
footer {
width: 100%;
height: 100px;
border-top: 1px solid #eaeaea;
display: flex;
justify-content: center;
align-items: center;
}
footer img {
margin-left: 0.5rem;
}
footer a {
display: flex;
justify-content: center;
align-items: center;
}
a {
color: inherit;
text-decoration: none;
}
code {
background: #fafafa;
border-radius: 5px;
padding: 0.75rem;
font-size: 1.1rem;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
Bitstream Vera Sans Mono, Courier New, monospace;
}
......@@ -72,5 +72,135 @@ exports[`renders homepage unchanged 1`] = `
</a>
</div>
</main>
<footer
className="footer"
>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
rel="noopener noreferrer"
target="_blank"
>
Powered by
<span
className="logo"
>
<span
style={
Object {
"background": "none",
"border": 0,
"boxSizing": "border-box",
"display": "inline-block",
"height": "initial",
"margin": 0,
"maxWidth": "100%",
"opacity": 1,
"overflow": "hidden",
"padding": 0,
"position": "relative",
"width": "initial",
}
}
>
<span
style={
Object {
"background": "none",
"border": 0,
"boxSizing": "border-box",
"display": "block",
"height": "initial",
"margin": 0,
"maxWidth": "100%",
"opacity": 1,
"padding": 0,
"width": "initial",
}
}
>
<img
alt=""
aria-hidden={true}
src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNzIiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmVyc2lvbj0iMS4xIi8+"
style={
Object {
"background": "none",
"border": 0,
"display": "block",
"height": "initial",
"margin": 0,
"maxWidth": "100%",
"opacity": 1,
"padding": 0,
"width": "initial",
}
}
/>
</span>
<img
alt="Vercel Logo"
data-nimg="intrinsic"
decoding="async"
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
style={
Object {
"border": "none",
"bottom": 0,
"boxSizing": "border-box",
"display": "block",
"height": 0,
"left": 0,
"margin": "auto",
"maxHeight": "100%",
"maxWidth": "100%",
"minHeight": "100%",
"minWidth": "100%",
"objectFit": undefined,
"objectPosition": undefined,
"padding": 0,
"position": "absolute",
"right": 0,
"top": 0,
"width": 0,
}
}
/>
<noscript>
<img
alt="Vercel Logo"
data-nimg="intrinsic"
decoding="async"
loading="lazy"
src="/_next/image?url=%2Fvercel.svg&w=256&q=75"
srcSet="/_next/image?url=%2Fvercel.svg&w=96&q=75 1x, /_next/image?url=%2Fvercel.svg&w=256&q=75 2x"
style={
Object {
"border": "none",
"bottom": 0,
"boxSizing": "border-box",
"display": "block",
"height": 0,
"left": 0,
"margin": "auto",
"maxHeight": "100%",
"maxWidth": "100%",
"minHeight": "100%",
"minWidth": "100%",
"objectFit": undefined,
"objectPosition": undefined,
"padding": 0,
"position": "absolute",
"right": 0,
"top": 0,
"width": 0,
}
}
/>
</noscript>
</span>
</span>
</a>
</footer>
</div>
`;
module.exports = {
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
],
moduleNameMapper: {
// Handle CSS imports (with CSS modules)
// https://jestjs.io/docs/webpack#mocking-css-modules
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
// Handle CSS imports (without CSS modules)
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js',
const nextJest = require('next/jest')
// Handle image imports
// https://jestjs.io/docs/webpack#handling-static-assets
'^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$': `<rootDir>/__mocks__/fileMock.js`,
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})
// Handle module aliases
'^@/components/(.*)$': '<rootDir>/components/$1',
},
// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
transform: {
// Use babel-jest to transpile tests with the next/babel preset
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you soon)
'^@/components/(.*)$': '<rootDir>/components/$1',
},
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
],
}
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
......@@ -21,8 +21,7 @@
"eslint": "7.32.0",
"eslint-config-next": "latest",
"eslint-plugin-testing-library": "4.11.0",
"identity-obj-proxy": "3.0.0",
"jest": "27.0.6",
"jest": "27.3.1",
"react-test-renderer": "17.0.2"
}
}
import Head from 'next/head'
import Image from 'next/image'
import styles from './index.module.css'
const Home = () => (
......@@ -42,6 +43,19 @@ const Home = () => (
</a>
</div>
</main>
<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<span className={styles.logo}>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
</footer>
</div>
)
......
......@@ -74,6 +74,11 @@
line-height: 1.5;
}
.logo {
height: 1em;
margin-left: 0.5rem;
}
@media (max-width: 600px) {
.grid {
width: 100%;
......
<svg width="283" height="64" viewBox="0 0 283 64" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/>
</svg>
\ No newline at end of file
<svg width="82" height="16" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path fill="url(#prefix__paint0_linear)" d="M9.018 0l9.019 16H0L9.018 0z"/>
<path fill="#333" fill-rule="evenodd" d="M51.634 12.028h-6.492V2.052h6.492v1.256H46.61v3.007h4.37V7.57h-4.37v3.202h5.024v1.255zm-14.063 0h-7.235v-1.096l5.342-7.624h-5.253V2.052h7.058v1.097l-5.342 7.623h5.43v1.256zm21.88 0h6.333v-1.256h-2.423V3.308h2.423V2.052h-6.332v1.256h2.441v7.465h-2.441v1.255zm18.22 0h-1.468v-8.72h-3.36V2.052h8.225v1.256H77.67v8.72z" clip-rule="evenodd"/>
<defs>
<linearGradient id="prefix__paint0_linear" x1="28.022" x2="16.189" y1="22.991" y2="8.569" gradientUnits="userSpaceOnUse">
<stop stop-color="#fff"/>
<stop offset="1"/>
</linearGradient>
</defs>
</svg>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment