
JavaScript TypeScript Jest
OfficialFreeMaster testing best practices with Jest.
Free · Opens the source repo
What JavaScript TypeScript Jest does
The JavaScript TypeScript Jest skill provides comprehensive guidance on best practices for writing tests using Jest, a popular testing framework for JavaScript and TypeScript applications. This skill covers essential topics such as test structure, effective mocking strategies, and techniques for testing asynchronous code. By following these practices, developers can ensure their code is well-tested and maintainable.
The skill emphasizes the importance of organizing tests clearly and logically. It advises on naming conventions for test files, the use of descriptive test names, and the organization of tests using nested describe blocks. This structure helps in understanding the purpose of each test at a glance, making it easier for teams to collaborate and maintain test suites over time.
Mocking is another critical aspect covered in this skill. It explains how to isolate tests by mocking external dependencies, which is vital for achieving reliable and fast test execution. The skill provides detailed instructions on using Jest's mocking utilities, such as jest.mock() and jest.spyOn(), ensuring that developers can effectively simulate various scenarios without relying on real external services.
Additionally, the skill includes guidance on snapshot testing for UI components, which is particularly useful for tracking changes in complex objects. It also highlights the importance of using React Testing Library for testing React components, focusing on user interactions and accessibility. Overall, this skill is an invaluable resource for developers looking to enhance their testing practices with Jest.
When to use it
Use this skill when you need to establish a robust testing framework for your JavaScript or TypeScript projects, especially when using Jest.
When not to use it
This skill may not be suitable for projects that do not use Jest or for teams already following a well-established testing methodology.
What you can build with it
Setting Up a Test Suite
When starting a new JavaScript or TypeScript project, use this skill to establish a well-structured test suite using Jest.
Mocking External APIs
If your application interacts with external APIs, this skill provides strategies for effectively mocking those dependencies in your tests.
Testing React Components
When developing React applications, leverage this skill to ensure your components are tested for user interactions and accessibility.
How to install JavaScript TypeScript Jest
View source1. Install with the skills CLI
npx skills add github/awesome-copilot/javascript-typescript-jest --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by githubTest Structure
- Name test files with
.test.tsor.test.jssuffix - 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()ormockReturnValue()to define mock behavior - Reset mocks between tests with
jest.resetAllMocks()inafterEach
Testing Async Code
- Always return promises or use async/await syntax in tests
- Use
resolves/rejectsmatchers 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
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)
Frequently asked questions about JavaScript TypeScript Jest
Similar skills
Quality Playbook Generator
Run comprehensive quality audits on any codebase.
PR Draft Summary
Automate PR summary generation for openai-agents-python.
Final Release Review
Streamline your release candidate audits with ease.
Unit Test Vue Pinia
Efficiently write and review unit tests for Vue 3 applications.
Slang Shader Expert
Optimize and integrate Slang shaders with ease.
Telemetry Standards
Ensure consistent event tracking in Supabase Studio.
