Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
React Testing Library を導入した (#432)
Browse files Browse the repository at this point in the history
* feat: 🎸 jest @testing-library/react @testing-library/jest-dom

* feat: 🎸 $ yarn add --dev jest-environment-jsdom

* test: 💍 Specを追加した
  • Loading branch information
nikukyugamer authored Jun 13, 2022
1 parent 14d8566 commit 18c783c
Show file tree
Hide file tree
Showing 5 changed files with 2,036 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect } from '@jest/globals'

import Contacts from '@/components/events-in-event/sosenkyo-book/Contacts'
import { render } from '@testing-library/react'

describe('pages/index の Home コンポーネント', () => {
it('期待どおりであること', () => {
const { getByText } = render(<Contacts />)

expect(getByText('[email protected]')).toBeTruthy()
})
})
10 changes: 10 additions & 0 deletions __tests__/pages/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { expect } from '@jest/globals'

// import Home from '@/pages/index'
// import { render } from '@testing-library/react'

describe('pages/index の Home コンポーネント', () => {
it('期待どおりであること', () => {
expect(1 + 2).toBe(3)
})
})
17 changes: 17 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const nextJest = require('next/jest')

const createJestConfig = nextJest({
dir: './',
})

const customJestConfig = {
testMatch: ['<rootDir>/__tests__/**/*.spec.(j|t)s?(x)'],
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// moduleDirectories: ['node_modules', '<rootDir>/'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1',
},
testEnvironment: 'jest-environment-jsdom',
}

module.exports = createJestConfig(customJestConfig)
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"react-dom": "18.1.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@types/node": "17.0.23",
"@types/react": "18.0.12",
"@types/react-burger-menu": "^2.8.3",
Expand All @@ -20,6 +22,8 @@
"eslint-config-prettier": "^8.5.0",
"gridjs": "^5.0.2",
"gridjs-react": "^5.0.2",
"jest": "^28.1.1",
"jest-environment-jsdom": "^28.1.1",
"npm-run-all": "^4.1.5",
"postcss": "8.4.14",
"prettier": "^2.6.2",
Expand Down
Loading

0 comments on commit 18c783c

Please sign in to comment.