mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 16:51:37 +00:00
Add testing
This commit is contained in:
4
.prettierrc.json
Normal file
4
.prettierrc.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": true
|
||||||
|
}
|
2
__mocks__/fileMock.ts
Normal file
2
__mocks__/fileMock.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/* eslint-disable import/no-anonymous-default-export */
|
||||||
|
export default 'test-file-stub';
|
2
__mocks__/styleMock.ts
Normal file
2
__mocks__/styleMock.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/* eslint-disable import/no-anonymous-default-export */
|
||||||
|
export default {};
|
16
__tests__/pages/index.test.tsx
Normal file
16
__tests__/pages/index.test.tsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* @jest-environment jsdom
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { render, screen } from '@testing-library/react';
|
||||||
|
import Home from 'pages/index';
|
||||||
|
|
||||||
|
describe('Home', () => {
|
||||||
|
it('renders a heading', () => {
|
||||||
|
render(<Home />);
|
||||||
|
|
||||||
|
const heading = screen.getByText(/hello/i);
|
||||||
|
|
||||||
|
expect(heading).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
18
jest.config.js
Normal file
18
jest.config.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// 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'],
|
||||||
|
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
|
||||||
|
moduleDirectories: ['node_modules', '<rootDir>/'],
|
||||||
|
testEnvironment: 'jest-environment-jsdom',
|
||||||
|
};
|
||||||
|
|
||||||
|
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
|
||||||
|
module.exports = createJestConfig(customJestConfig);
|
6
jest.setup.js
Normal file
6
jest.setup.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
// 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';
|
7
layouts/MainLayout.tsx
Normal file
7
layouts/MainLayout.tsx
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { FC } from 'react';
|
||||||
|
|
||||||
|
const MainLayout: FC = () => {
|
||||||
|
return <></>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MainLayout;
|
@ -5,7 +5,9 @@
|
|||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint"
|
"lint": "next lint",
|
||||||
|
"test": "jest --watch",
|
||||||
|
"test:coverage": "CI=true yarn test --env=jsdom --coverage"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mdx-js/loader": "^1.6.22",
|
"@mdx-js/loader": "^1.6.22",
|
||||||
@ -16,6 +18,9 @@
|
|||||||
"react-dom": "^17.0.2"
|
"react-dom": "^17.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@testing-library/jest-dom": "^5.16.1",
|
||||||
|
"@testing-library/react": "^12.1.2",
|
||||||
|
"@types/jest": "^27.4.0",
|
||||||
"@types/mdx-js__react": "^1.5.5",
|
"@types/mdx-js__react": "^1.5.5",
|
||||||
"@types/node": "17.0.8",
|
"@types/node": "17.0.8",
|
||||||
"@types/react": "17.0.38",
|
"@types/react": "17.0.38",
|
||||||
@ -23,6 +28,7 @@
|
|||||||
"classnames": "^2.3.1",
|
"classnames": "^2.3.1",
|
||||||
"eslint": "8.6.0",
|
"eslint": "8.6.0",
|
||||||
"eslint-config-next": "12.0.8",
|
"eslint-config-next": "12.0.8",
|
||||||
|
"jest": "^27.4.7",
|
||||||
"postcss": "^8.4.5",
|
"postcss": "^8.4.5",
|
||||||
"tailwindcss": "^3.0.13",
|
"tailwindcss": "^3.0.13",
|
||||||
"typescript": "4.5.4"
|
"typescript": "4.5.4"
|
||||||
|
Reference in New Issue
Block a user