generated from Team-INSERT/Repository-generator-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from Team-INSERT/test/useModal
useModal 테스트 코드 작성
- Loading branch information
Showing
14 changed files
with
786 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
jest.config.js | ||
next.config.js | ||
jest.setup.js | ||
next.config.js | ||
commitlint.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,6 @@ yarn-error.log* | |
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
# Sentry Config File | ||
.sentryclirc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,10 @@ | ||
// jest.config.js | ||
module.exports = { | ||
collectCoverage: true, | ||
// on node 14.x coverage provider v8 offers good speed and more or less good report | ||
coverageProvider: "v8", | ||
collectCoverageFrom: [ | ||
"**/*.{js,jsx,ts,tsx}", | ||
"!**/e2e/**", | ||
"!**/*.d.ts", | ||
"!**/node_modules/**", | ||
"!<rootDir>/out/**", | ||
"!<rootDir>/.next/**", | ||
"!<rootDir>/*.config.js", | ||
"!<rootDir>/*.config.ts", | ||
"!<rootDir>/*rc.js", | ||
"!<rootDir>/coverage/**", | ||
], | ||
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 | ||
"^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i": `<rootDir>/__mocks__/fileMock.js`, | ||
|
||
// Handle module aliases | ||
"^@/components/(.*)$": "<rootDir>/components/$1", | ||
}, | ||
// Add more setup options before each test is run | ||
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], | ||
testPathIgnorePatterns: [ | ||
"<rootDir>/node_modules/", | ||
"<rootDir>/.next/", | ||
"<rootDir>/e2e/", | ||
], | ||
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)$", | ||
], | ||
const nextJest = require("next/jest"); | ||
const createJestConfig = nextJest({ | ||
dir: "./", | ||
}); | ||
const customJestConfig = { | ||
setupFilesAfterEnv: ["<rootDir>/setupTests.ts"], | ||
moduleDirectories: ["node_modules", "<rootDir>/"], | ||
testEnvironment: "jest-environment-jsdom", | ||
}; | ||
module.exports = createJestConfig(customJestConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// This file configures the initialization of Sentry on the client. | ||
// The config you add here will be used whenever a users loads a page in their browser. | ||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/ | ||
|
||
import * as Sentry from "@sentry/nextjs"; | ||
|
||
Sentry.init({ | ||
dsn: "https://d9b95ec831a783292206973ebf392318@o4506432587563008.ingest.sentry.io/4506432597262336", | ||
|
||
// Adjust this value in production, or use tracesSampler for greater control | ||
tracesSampleRate: 1, | ||
|
||
// Setting this option to true will print useful information to the console while you're setting up Sentry. | ||
debug: false, | ||
|
||
replaysOnErrorSampleRate: 1.0, | ||
|
||
// This sets the sample rate to be 10%. You may want this to be 100% while | ||
// in development and sample at a lower rate in production | ||
replaysSessionSampleRate: 0.1, | ||
|
||
// You can remove this option if you're not planning to use the Sentry Session Replay feature: | ||
integrations: [ | ||
new Sentry.Replay({ | ||
// Additional Replay configuration goes in here, for example: | ||
maskAllText: true, | ||
blockAllMedia: true, | ||
}), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on). | ||
// The config you add here will be used whenever one of the edge features is loaded. | ||
// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally. | ||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/ | ||
|
||
import * as Sentry from "@sentry/nextjs"; | ||
|
||
Sentry.init({ | ||
dsn: "https://d9b95ec831a783292206973ebf392318@o4506432587563008.ingest.sentry.io/4506432597262336", | ||
|
||
// Adjust this value in production, or use tracesSampler for greater control | ||
tracesSampleRate: 1, | ||
|
||
// Setting this option to true will print useful information to the console while you're setting up Sentry. | ||
debug: false, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// This file configures the initialization of Sentry on the server. | ||
// The config you add here will be used whenever the server handles a request. | ||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/ | ||
|
||
import * as Sentry from "@sentry/nextjs"; | ||
|
||
Sentry.init({ | ||
dsn: "https://d9b95ec831a783292206973ebf392318@o4506432587563008.ingest.sentry.io/4506432597262336", | ||
|
||
// Adjust this value in production, or use tracesSampler for greater control | ||
tracesSampleRate: 1, | ||
|
||
// Setting this option to true will print useful information to the console while you're setting up Sentry. | ||
debug: false, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "@testing-library/jest-dom"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import useModal from "./useModal"; | ||
|
||
jest.mock("./useModal"); | ||
|
||
const TestComponent = () => { | ||
const { openModal, closeModal } = useModal(); | ||
return ( | ||
<div> | ||
<button onClick={() => openModal({ component: <></> })}>Open</button> | ||
<button onClick={closeModal}>Close</button> | ||
</div> | ||
); | ||
}; | ||
|
||
describe("useModal", () => { | ||
const mockUseModal = useModal as jest.MockedFunction<typeof useModal>; | ||
mockUseModal.mockReturnValue({ | ||
openModal: jest.fn(), | ||
closeModal: jest.fn(), | ||
visible: false, | ||
}); | ||
|
||
it("openModal이 호출되면 화면에 모달이 render 되어야 한다", async () => { | ||
render(<TestComponent />); | ||
|
||
fireEvent.click(screen.getByRole("button", { name: "Open" })); | ||
expect(mockUseModal().openModal).toHaveBeenCalled(); | ||
expect(document.activeElement).toBeInstanceOf(HTMLElement); | ||
}); | ||
|
||
it("closeModal이 호출되면 화면에 render된 모달이 unmount 되어야 한다.", () => { | ||
render(<TestComponent />); | ||
|
||
fireEvent.click(screen.getByRole("button", { name: "Close" })); | ||
expect(mockUseModal().closeModal).toHaveBeenCalled(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.