Best practices for writing JavaScript/TypeScript tests using Jest, including mocking strategies, test structure, and common patterns.
.test.ts or .test.js suffix__tests__ directorydescribe('Component/Function/Class', () => { it('should do something', () => {}) })jest.mock() for module-level mocksjest.spyOn() for specific function mocksmockImplementation() or mockReturnValue() to define mock behaviorjest.resetAllMocks() in afterEachresolves/rejects matchers for promisesjest.setTimeout()userEvent over fireEvent for more realistic user interactionsexpect(value).toBe(expected), expect(value).toEqual(expected)expect(value).toBeTruthy(), expect(value).toBeFalsy()expect(value).toBeGreaterThan(3), expect(value).toBeLessThanOrEqual(3)expect(value).toMatch(/pattern/), expect(value).toContain('substring')expect(array).toContain(item), expect(array).toHaveLength(3)expect(object).toHaveProperty('key', value)expect(fn).toThrow(), expect(fn).toThrow(Error)expect(mockFn).toHaveBeenCalled(), expect(mockFn).toHaveBeenCalledWith(arg1, arg2)Copy a source-pinned command for your client. You run it yourself.
Destination: .claude/skills/javascript-typescript-jest · pinned to the source commit
# Run from your project root
git clone https://github.com/github/awesome-copilot.git .skillboard-tmp
git -C .skillboard-tmp checkout f11a4e441c5ff061b4f8ae37952be8c602e4034e
mkdir -p ".claude/skills"
cp -r ".skillboard-tmp/skills/javascript-typescript-jest" ".claude/skills/"
rm -rf .skillboard-tmpReview the source before running. This copies files into your project; it is not a one-click install and does not verify runtime safety.
sudo apt update && sudo apt install -y gitnpm install -g @anthropic-ai/claude-code# Run from your project root
git clone https://github.com/github/awesome-copilot.git .skillboard-tmp
git -C .skillboard-tmp checkout f11a4e441c5ff061b4f8ae37952be8c602e4034e
mkdir -p ".claude/skills"
cp -r ".skillboard-tmp/skills/javascript-typescript-jest" ".claude/skills/"
rm -rf .skillboard-tmpDestination: .claude/skills/javascript-typescript-jest
Scanner static-checks@0.1.0 · commit f11a4e441c5f. Static checks cannot prove runtime safety – review the source and the exact diff before installing. How checks work.
No static rules matched. This is not a safety guarantee.