Basic testing setup

This commit is contained in:
David
2021-03-11 16:46:55 +01:00
parent a19e85df61
commit 6ca471af5f
6 changed files with 6272 additions and 2 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
*.config.js linguist-detectable=false

13
__tests__/Error.test.tsx Normal file
View File

@@ -0,0 +1,13 @@
import { render, screen } from "@testing-library/react";
import Error from "next/error";
it("renders a not found message on 404 code", () => {
render(<Error statusCode={404} />);
expect(screen.getByText(/this page could not be found/i)).toBeVisible();
});
it("renders the correct status code", () => {
const code = Math.floor(Math.random() * 500) + 100;
render(<Error statusCode={code} />);
expect(screen.getByText(code)).toBeVisible();
});

17
jest.config.js Normal file
View File

@@ -0,0 +1,17 @@
module.exports = {
transform: {
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest'
},
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$',
'^.+\\.module\\.(css|sass|scss)$',
],
testMatch: [
'<rootDir>/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/**/*.{spec,test}.{js,jsx,ts,tsx}',
],
setupFilesAfterEnv: [
"<rootDir>/setupTests.ts"
],
moduleFileExtensions: ["ts", "tsx", "js", "jsx"]
}

View File

@@ -6,7 +6,8 @@
"dev": "next dev", "dev": "next dev",
"debug": "NODE_OPTIONS='--inspect' next dev", "debug": "NODE_OPTIONS='--inspect' next dev",
"build": "next build", "build": "next build",
"start": "next start" "start": "next start",
"test": "jest"
}, },
"dependencies": { "dependencies": {
"cheerio": "^1.0.0-rc.5", "cheerio": "^1.0.0-rc.5",
@@ -15,6 +16,10 @@
"react-dom": "17.0.1" "react-dom": "17.0.1"
}, },
"devDependencies": { "devDependencies": {
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.8.3",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.33", "@types/node": "^14.14.33",
"@types/react": "^17.0.3", "@types/react": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^4.0.0", "@typescript-eslint/eslint-plugin": "^4.0.0",
@@ -24,14 +29,21 @@
"eslint-config-react-app": "^6.0.0", "eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.2.0", "eslint-plugin-flowtype": "^5.2.0",
"eslint-plugin-import": "^2.22.0", "eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^24.0.0",
"eslint-plugin-jsx-a11y": "^6.3.1", "eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.20.3", "eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.8", "eslint-plugin-react-hooks": "^4.0.8",
"eslint-plugin-testing-library": "^3.9.0",
"jest": "^26.6.3",
"typescript": "^4.2.3" "typescript": "^4.2.3"
}, },
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
"react-app" "react-app",
"react-app/jest"
] ]
},
"babel": {
"presets": ["next/babel"]
} }
} }

1
setupTests.ts Normal file
View File

@@ -0,0 +1 @@
import '@testing-library/jest-dom';

6226
yarn.lock Normal file

File diff suppressed because it is too large Load Diff