-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(apply): force to node 18.0.0 and configure unit test environments
- Loading branch information
1 parent
eb83941
commit 57b8114
Showing
10 changed files
with
7,441 additions
and
7,519 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,8 +1,15 @@ | ||
module.exports = { | ||
const config = { | ||
stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"], | ||
addons: [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/preset-create-react-app", | ||
], | ||
framework: { | ||
name: "@storybook/react-webpack5", | ||
options: { fastRefresh: true }, | ||
}, | ||
staticDirs: ["../public"], | ||
}; | ||
|
||
export default config; |
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
2 changes: 1 addition & 1 deletion
2
...ponents/@common/Button/Button.stories.tsx → ...ommon/Button/__tests__/Button.stories.tsx
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
18 changes: 18 additions & 0 deletions
18
frontend/src/components/@common/Button/__tests__/Button.test.tsx
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,18 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import Button from "../Button"; | ||
|
||
describe("Button 컴포넌트", () => { | ||
test("Button을 렌더할 수 있어야 한다.", () => { | ||
render(<Button />); | ||
|
||
expect(screen.getByRole("button")).toBeInTheDocument(); | ||
}); | ||
|
||
test("버튼 텍스트와 함께 Button을 렌더할 수 있어야 한다.", () => { | ||
const label = "button label"; | ||
|
||
render(<Button>{label}</Button>); | ||
|
||
expect(screen.getByText(label)).toBeInTheDocument(); | ||
}); | ||
}); |
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,48 @@ | ||
import { renderHook } from "@testing-library/react"; | ||
import { describe, expect, test } from "@jest/globals"; | ||
|
||
import useInterval from "../useInterval"; | ||
|
||
describe("useInterval", () => { | ||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.runOnlyPendingTimers(); | ||
jest.useRealTimers(); | ||
}); | ||
|
||
test("처음 렌더될 때는 콜백을 호출하지 않아야 한다.", () => { | ||
const callback = jest.fn(); | ||
const delay = 1000; | ||
|
||
const { unmount } = renderHook(() => useInterval(callback, delay)); | ||
|
||
expect(callback).not.toHaveBeenCalled(); | ||
unmount(); | ||
}); | ||
|
||
test("지정된 시간 간격으로 콜백을 호출해야 한다.", () => { | ||
const callback = jest.fn(); | ||
const delay = 1000; | ||
const callCount = 3; | ||
|
||
const { unmount } = renderHook(() => useInterval(callback, delay)); | ||
jest.advanceTimersByTime(delay * callCount); | ||
|
||
expect(callback).toHaveBeenCalledTimes(callCount); | ||
unmount(); | ||
}); | ||
|
||
test("훅을 사용하는 컴포넌트가 unmount된 이후에는 시간이 지나도 지정된 콜백이 호출되지 않아야 한다.", () => { | ||
const callback = jest.fn(); | ||
const delay = 1000; | ||
|
||
const { unmount } = renderHook(() => useInterval(callback, delay)); | ||
unmount(); | ||
jest.advanceTimersByTime(delay); | ||
|
||
expect(callback).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
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,3 @@ | ||
// react-testing-library renders your components to document.body, | ||
// this adds jest-dom's custom assertions | ||
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,12 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import { PHONE_NUMBER_HYPHEN_IDX, formatHyphen } from "../phoneNumber"; | ||
|
||
describe("Format phoneNumber", () => { | ||
test("01012345678 -> 010-1234-5678", () => { | ||
const [firstHyphenIdx, secondHyphenIdx] = PHONE_NUMBER_HYPHEN_IDX; | ||
|
||
const formattedNumber = formatHyphen("01012345678", firstHyphenIdx, secondHyphenIdx); | ||
|
||
expect(formattedNumber).toBe("010-1234-5678"); | ||
}); | ||
}); |
Oops, something went wrong.