{"id":"fa9063f6-4792-456d-a9b2-f629b4f16743","slug":"javascript-typescript-jest","kind":"skill","name":"javascript-typescript-jest","summary":"Best practices for writing JavaScript/TypeScript tests using Jest, including mocking strategies, test structure, and common patterns.","owner":"github","repoUrl":"https://github.com/github/awesome-copilot/tree/HEAD/skills/javascript-typescript-jest","license":"MIT","licenseTier":"permissive","trust":"official","stars":39994,"match":null,"fewStars":false,"format":"skill","createdAt":null,"addedAt":"2026-10-14T05:13:39.778Z","logoUrl":"https://avatars.githubusercontent.com/u/9919?v=4","linkOnly":false,"collection":{"name":"awesome-copilot","repo":"github/awesome-copilot"},"skillPath":"skills/javascript-typescript-jest","categories":["developer-tools","writing"],"tags":["ai","github-copilot","prompt-engineering","hacktoberfest","agents","awesome","custom-agents"],"runtime":"binary","local":true,"cloudCapable":false,"cloudCapability":"unknown","cloudReadyOnPlatform":false,"needsApiKey":false,"reviewed":false,"syncedAt":"2026-10-14T05:13:39.777Z","sample":false,"url":"https://conduits.dev/tools/javascript-typescript-jest","language":"JavaScript","transports":[],"install":{},"requirements":{"env":[],"upstreamMayCharge":false},"tools":null,"readme":"### Test Structure\n- Name test files with `.test.ts` or `.test.js` suffix\n- Place test files next to the code they test or in a dedicated `__tests__` directory\n- Use descriptive test names that explain the expected behavior\n- Use nested describe blocks to organize related tests\n- Follow the pattern: `describe('Component/Function/Class', () => { it('should do something', () => {}) })`\n\n### Effective Mocking\n- Mock external dependencies (APIs, databases, etc.) to isolate your tests\n- Use `jest.mock()` for module-level mocks\n- Use `jest.spyOn()` for specific function mocks\n- Use `mockImplementation()` or `mockReturnValue()` to define mock behavior\n- Reset mocks between tests with `jest.resetAllMocks()` in `afterEach`\n\n### Testing Async Code\n- Always return promises or use async/await syntax in tests\n- Use `resolves`/`rejects` matchers for promises\n- Set appropriate timeouts for slow tests with `jest.setTimeout()`\n\n### Snapshot Testing\n- Use snapshot tests for UI components or complex objects that change infrequently\n- Keep snapshots small and focused\n- Review snapshot changes carefully before committing\n\n### Testing React Components\n- Use React Testing Library over Enzyme for testing components\n- Test user behavior and component accessibility\n- Query elements by accessibility roles, labels, or text content\n- Use `userEvent` over `fireEvent` for more realistic user interactions\n\n## Common Jest Matchers\n- Basic: `expect(value).toBe(expected)`, `expect(value).toEqual(expected)`\n- Truthiness: `expect(value).toBeTruthy()`, `expect(value).toBeFalsy()`\n- Numbers: `expect(value).toBeGreaterThan(3)`, `expect(value).toBeLessThanOrEqual(3)`\n- Strings: `expect(value).toMatch(/pattern/)`, `expect(value).toContain('substring')`\n- Arrays: `expect(array).toContain(item)`, `expect(array).toHaveLength(3)`\n- Objects: `expect(object).toHaveProperty('key', value)`\n- Exceptions: `expect(fn).toThrow()`, `expect(fn).toThrow(Error)`\n- Mock functions: `expect(mockFn).toHaveBeenCalled()`, `expect(mockFn).toHaveBeenCalledWith(arg1, arg2)`"}