Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
直接コマンドでは確認用 Prompt が省略されます。実行前にソースを確認してください。
npx skills add https://github.com/dipro-vn/dipro-ai-boost --skill testing-jest-mockingコマンドは1行のまま表示されます。コピー前に横へスクロールして全体を確認してください。
ローカルで確認しますか?SkillsMP が現在取得できるファイルをダウンロードできます。
SOC 職業分類に基づく
SKILL.md を表示中
| name | testing-jest-mocking |
| description | null |
Category: testing-jest · Status: 🟢 Active
Khi cần mock module/function/timer hoặc giả lập API (msw) trong test.
jest.mock('module') cho dependency; jest.fn() cho callback; jest.spyOn khi cần giữ impl thật.msw chặn ở tầng network thay vì mock fetch thủ công.jest.useFakeTimers() + advanceTimersByTime; nhớ restore.clearMocks/resetMocks để tránh rò trạng thái.jest.mock('@/lib/api');
import { getUser } from '@/lib/api';
beforeEach(() => jest.clearAllMocks());
it('hiển thị tên user', async () => {
(getUser as jest.Mock).mockResolvedValue({ name: 'An' });
render(<Profile id="1" />);
expect(await screen.findByText('An')).toBeInTheDocument();
});
Good: mock ở ranh giới network/module, dùng msw cho API, reset mock mỗi test. Avoid: mock quá sâu khiến test vô nghĩa, quên restore timer, để mock rò qua test khác.