MR
Mayur Rathi
@github
⭐ 34.1k GitHub stars

Javascript-Typescript-Jest

Javascript-Typescript-Jest是一款code方向的AI技能,核心价值是Best practices for writing JavaScript/TypeScript tests using Jest, including mocking strategies, test structure, and common patterns,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。

Best practices for writing JavaScript/TypeScript tests using Jest, including mocking strategies, test structure, and common patterns.

Last verified on: 2026-05-30
mkdir -p ./skills/javascript-typescript-jest && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/javascript-typescript-jest/SKILL.md -o ./skills/javascript-typescript-jest/SKILL.md

Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).

Skill Content

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)`

🎯 Best For

  • QA engineers
  • Developers writing unit tests
  • Claude users
  • GitHub Copilot users
  • Software engineers

💡 Use Cases

  • Generating test cases for edge conditions
  • Writing integration test suites
  • TypeScript type safety checking
  • Module refactoring

📖 How to Use This Skill

  1. 1

    Install the Skill

    Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.

  2. 2

    Load into Your AI Assistant

    Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.

  3. 3

    Apply Javascript-Typescript-Jest to Your Work

    Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.

  4. 4

    Review and Refine

    Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.

❓ Frequently Asked Questions

Does this generate test mocks?

Many testing skills include mock generation. Check the install command and skill content for details.

Is Javascript-Typescript-Jest compatible with Cursor and VS Code?

Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.

Do I need specific dependencies for Javascript-Typescript-Jest?

Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.

How do I install Javascript-Typescript-Jest?

Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/javascript-typescript-jest/SKILL.md, ready to use.

Can I customize this skill for my team?

Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.

⚠️ Common Mistakes to Avoid

Not testing edge cases

AI tends to generate happy-path tests. Manually review for boundary conditions.

Skipping validation

Always test AI-generated code changes, even for simple refactors.

Missing dependency updates

Check if the skill requires updated dependencies or new packages.

🔗 Related Skills