javascript-typescript-jest — GitHub Copilot testing skill
This skill guides GitHub Copilot in writing JavaScript and TypeScript tests with Jest. Use it when you want concrete patterns for mocks, async tests, and test organization.
npx skills add github/awesome-copilot --skill javascript-typescript-jestWhat javascript-typescript-jest does
The skill recommends .test.ts or .test.js filenames and placing tests beside the code under test or in an __tests__ directory. It covers grouping cases with describe and it, common Jest matchers, exception checks, and focused snapshots.
For isolation, it describes jest.mock() and jest.spyOn(), setting mock behavior with mockImplementation() or mockReturnValue(), and clearing mocks in afterEach. Async tests should return promises or use async/await; resolves and rejects handle promise outcomes. Slow tests can use jest.setTimeout().
For React, the skill favors React Testing Library over Enzyme and suggests querying by accessibility role, label, or text. It provides testing guidance, not project setup. Install it when Copilot needs Jest-specific direction; skip it if your project does not use Jest.
What it helps with
- organize test files alongside the code they cover
- isolate tests from API or database dependencies with mocks
- check promise results and rejected async calls
- query React components by accessible roles and labels
- keep snapshots focused and reviewable
Example prompts for the agent
- Write Jest tests for this function using descriptive `describe` and `it` blocks.
- Mock the external API with `jest.mock()` and reset mocks after each test.
- Test this React component with React Testing Library and query by accessibility role.
How to install javascript-typescript-jest
1Skills CLI (Vercel)
npx skills add github/awesome-copilot --skill javascript-typescript-jest2GitHub CLI
gh skill install github/awesome-copilot javascript-typescript-jest3Manually: put the files in place
.github/skills/javascript-typescript-jest/SKILL.md1Skills CLI (Vercel)
npx skills add github/awesome-copilot --skill javascript-typescript-jest -a claude-code2Manually: put the files in place
~/.claude/skills/javascript-typescript-jest/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/javascript-typescript-jest/
Manually: put the files in place
.agents/skills/javascript-typescript-jest/SKILL.mdFor all projects use ~/.agents/skills/
Manually: put the files in place
.cursor/skills/javascript-typescript-jest/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
Platform CLI
gemini skills install https://github.com/github/awesome-copilot --path skills/javascript-typescript-jestManually: put the files in place
.devin/skills/javascript-typescript-jest/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
From the same set554
The whole set →Similar
Questions about javascript-typescript-jest
How do I install javascript-typescript-jest in GitHub Copilot?
Run npx skills add github/awesome-copilot --skill javascript-typescript-jest or gh skill install github/awesome-copilot javascript-typescript-jest.
What does javascript-typescript-jest do?
It gives Copilot patterns for JavaScript and TypeScript tests with Jest, including test structure, mocking, async checks, and matchers.
What does the skill recommend for React component tests?
It recommends React Testing Library over Enzyme, checking user behavior and accessibility, and querying by role, label, or text. Use userEvent for interactions rather than fireEvent.
Source text
SKILL.md · MIT
---
name: javascript-typescript-jest
description: 'Best practices for writing JavaScript/TypeScript tests using Jest, including mocking strategies, test structure, and common patterns.'
---
### Test Structure
- Name test files with `.test.ts` or `.test.js` suffix
- Place test files next to the code they test or in a dedicated `__tests__` directory
- Use descriptive test names that explain the expected behavior
- Use nested describe blocks to organize related tests
- Follow the pattern: `describe('Component/Function/Class', () => { it('should do something', () => {}) })`
### Effective Mocking
- Mock external dependencies (APIs, databases, etc.) to isolate your tests
- Use `jest.mock()` for module-level mocks
- Use `jest.spyOn()` for specific function mocks
- Use `mockImplementation()` or `mockReturnValue()` to define mock behavior
- Reset mocks between tests with `jest.resetAllMocks()` in `afterEach`
### Testing Async Code
- Always return promises or use async/await syntax in tests
- Use `resolves`/`rejects` matchers for promises
- Set appropriate timeouts for slow tests with `jest.setTimeout()`
### Snapshot Testing
- Use snapshot tests for UI components or complex objects that change infrequently
- Keep snapshots small and focused
- Review snapshot changes carefully before committing
### Testing React Components
- Use React Testing Library over Enzyme for testing components
- Test user behavior and component accessibility
- Query elements by accessibility roles, labels, or text content
- Use `userEvent` over `fireEvent` for more realistic user interactions
## Common Jest Matchers
- Basic: `expect(value).toBe(expected)`, `expect(value).toEqual(expected)`
- Truthiness: `expect(value).toBeTruthy()`, `expect(value).toBeFalsy()`
- Numbers: `expect(value).toBeGreaterThan(3)`, `expect(value).toBeLessThanOrEqual(3)`
- Strings: `expect(value).toMatch(/pattern/)`, `expect(value).toContain('substring')`
- Arrays: `expect(array).toContain(item)`, `expect(array).toHaveLength(3)`
- Objects: `expect(object).toHaveProperty('key', value)`
- Exceptions: `expect(fn).toThrow()`, `expect(fn).toThrow(Error)`
- Mock functions: `expect(mockFn).toHaveBeenCalled()`, `expect(mockFn).toHaveBeenCalledWith(arg1, arg2)`
© github · MIT · github/awesome-copilot