Javascript Typescript Jest
GitHubOfficialOriginally contributed by @aaronpowell as prompts/javascript-typescript-jest.prompt.md; moved into a skill by pull request #761Distributed by GitHub
- Skill
- Guidelines
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured set of guidelines for implementing robust test suites in JavaScript and TypeScript environments using Jest. It covers essential testing methodologies, including proper test organization, effective mocking strategies for external dependencies, handling asynchronous code, and utilizing snapshot testing. Additionally, it offers specific recommendations for testing React components using the React Testing Library and provides a quick reference for common Jest matchers to streamline the assertion process.
What it does
- Defines standard file naming and directory structures for test files.
- Outlines strategies for mocking modules and functions to isolate test logic.
- Provides patterns for testing asynchronous operations and promise-based code.
- Offers best practices for snapshot testing of UI components and complex objects.
- Recommends user-centric testing approaches for React applications.
- Summarizes essential Jest matchers for common data types and mock verification.
When to use it
- When setting up a new testing suite for a JavaScript or TypeScript project.
- When standardizing test writing practices across a development team.
- When troubleshooting or refactoring existing Jest test suites.
- When looking for guidance on mocking external dependencies or APIs.
- When writing tests for React components to ensure accessibility and realistic user interaction.
Advantages
- Promotes consistent and readable test code across projects.
- Helps isolate code logic through effective mocking techniques.
- Encourages testing user behavior rather than implementation details in React.
- Provides a quick reference for common matchers and testing patterns.
Usage examples
- “How should I organize my test files in a TypeScript project?”
- The skill recommends naming files with .test.ts suffixes and placing them either next to the source code or in a dedicated __tests__ directory.
- “What is the best way to mock an API call in Jest?”
- The skill advises using jest.mock() for module-level mocks or jest.spyOn() for specific functions, along with mockImplementation() to define behavior.
- “How do I test an async function that returns a promise?”
- The skill suggests using async/await syntax or the .resolves/.rejects matchers to handle promise-based assertions correctly.
- “Should I use fireEvent or userEvent for React tests?”
- The skill recommends using userEvent over fireEvent to simulate more realistic user interactions during component testing.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/github/javascript-typescript-jest/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip javascript-typescript-jest.zip -d .agents/skills
Documentation by aaronpowell
Test Structure
Name test files with
.test.tsor.test.jssuffixPlace test files next to the code they test or in a dedicated
__tests__directoryUse 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 mocksUse
jest.spyOn()for specific function mocksUse
mockImplementation()ormockReturnValue()to define mock behaviorReset mocks between tests with
jest.resetAllMocks()inafterEach
Testing Async Code
Always return promises or use async/await syntax in tests
Use
resolves/rejectsmatchers for promisesSet 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
userEventoverfireEventfor 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)
Files
- ATTRIBUTION.mdAdded by AutoGineer1.2 KiB
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md2.2 KiB
SKILL.md
Test Structure
Name test files with
.test.tsor.test.jssuffixPlace test files next to the code they test or in a dedicated
__tests__directoryUse 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 mocksUse
jest.spyOn()for specific function mocksUse
mockImplementation()ormockReturnValue()to define mock behaviorReset mocks between tests with
jest.resetAllMocks()inafterEach
Testing Async Code
Always return promises or use async/await syntax in tests
Use
resolves/rejectsmatchers for promisesSet 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
userEventoverfireEventfor 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)
Requirements and compatibility
Written for: GitHub Copilot
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Originally contributed by
@aaronpowellas prompts/javascript-typescript-jest.prompt.mdmoved into a skill by pull request #761
- Publisher
- GitHub (Official)
- Distributed by
- GitHub
- Source
- github/awesome-copilot · skills/javascript-typescript-jest · commit 797337f
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
- Contributors
- aaronpowell, jamesmontemagno
AutoGineer is not affiliated with or endorsed by aaronpowell or GitHub.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download javascript-typescript-jest.zip