Skip to content
Snippets Groups Projects
Commit b6391e9c authored by Serdar D's avatar Serdar D
Browse files

jest aufgesetzt und ersten falschen test geschrieben

parent 76b62f3f
No related branches found
No related tags found
1 merge request!33Testing
Pipeline #38604 passed
/* eslint-disable testing-library/no-unnecessary-act */
import { render, screen, waitFor } from '@testing-library/react';
import { ErrorBoundary } from 'react-error-boundary';
import ErrorFallback from '../ErrorFallback';
import Shopper from '../Shopper';
import { shopper } from './data';
test("Shopper Test mit fetch und mockup", async () => {
jest.spyOn(global, "fetch").mockImplementation(() =>
Promise.resolve({
ok: true,
json: () => Promise.resolve(shopper)
} as Response)
);
//ErrorBoundary ist notwendig, da sonst der Fehler nicht abgefangen wird.(in FallbackCompontent wird der Fehler behandelt)
render(
<ErrorBoundary
FallbackComponent={ErrorFallback}>
<Shopper />
</ErrorBoundary>
);
await waitFor(() => {
const titleTest = screen.getAllByText(shopper.shopLists[0].store);
expect(titleTest.length).toBeGreaterThan(0);
}, { timeout: 1000 });
expect(global.fetch).toHaveBeenCalledTimes(1);
});
\ No newline at end of file
const nextJest = require('next/jest')
const createJestConfig = nextJest({
//Provide the path to your Next.js app to load next.config.js and .env in your test environment.
dir: '.',
})
// Add your custom config to be passed to Jest.
const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleNameMapper: {
//Handle module aliases (this will be automatically configured for you soon)
'^@app/api/(.*)$': '<rootDir>/app/api/$1',
},
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)
\ No newline at end of file
import '@testing-library/jest-dom/extend-expect';
This diff is collapsed.
......@@ -9,7 +9,9 @@
"start": "next start",
"lint": "next lint",
"preview": "next build && next start",
"vercel-build": "prisma generate && prisma migrate deploy && next build"
"vercel-build": "prisma generate && prisma migrate deploy && next build",
"test": "jest",
"coverage": "jest --coverage"
},
"dependencies": {
"@auth/prisma-adapter": "^1.0.0",
......@@ -44,6 +46,8 @@
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^4.29.9",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@types/bcrypt": "^5.0.0",
"@types/node": "^20.3.1",
"@types/react": "^18.2.13",
......@@ -51,6 +55,8 @@
"autoprefixer": "10.4.14",
"eslint": "^8.43.0",
"eslint-config-next": "^13.4.6",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"postcss": "8.4.24",
"prisma": "^4.15.0",
"tailwindcss": "3.3.2",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment