javascript-typescript-jest
Skill1 starsChanged 35 days agoMITView on GitHub
Jest/Vitest testing patterns for JS/TS — mocking, spies, snapshots, async tests, structure. Use when: 'write a jest test', 'write a vitest test', 'mock this module', 'spy on a function', 'snapshot test', 'set up jest', 'fix a flaky test', 'write tests', 'unit test this', 'add tests for', or reviewing existing Jest/Vitest tests. Vitest has a compatible API — patterns apply to both.
2 other projects use a version of this, 2 of them edited.
Adopted by
Most recently taken up by
- github/awesome-copilotedited, first seen Oct 25, 2026
- ReaperOAK/ForgeOSedited, first seen Jun 8, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 2
- github/awesome-copilot★ 42k92% same
- ReaperOAK/ForgeOS★ 092% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- appinsights-instrumentationSkill
- csharp-toolkitSkill
- delegateSkill
- deploy-verifySkill
- diagnoseSkill
- documentation-writerSkill
- flywheelSkill
- grill-meSkill
- microsoft-docsSkill
- nuget-managerSkill
- performance-optimizationSkill
- python-fastapi-pytestSkill
- sql-toolkitSkill
- tddSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 7 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Place test files next to the code they test or in a dedicated __tests__ directory
- Distinctive: line 15
Use descriptive test names that explain the expected behavior
- Distinctive: line 16
Use nested describe blocks to organize related tests
- Very specific: line 17
Follow the pattern: describe('Component/Function/Class', () => { it('should do something', () => {}) })
- Very specific: line 21
Use jest.mock() for module-level mocks
- Very specific: line 22
Use jest.spyOn() for specific function mocks
- Very specific: line 23
Use mockImplementation() or mockReturnValue() to define mock behavior
- Distinctive: line 27
Always return promises or use async/await syntax in tests
- Very specific: line 28
Use resolves/rejects matchers for promises
- Distinctive: line 32
Use snapshot tests for UI components or complex objects that change infrequently
- Distinctive: line 33
Keep snapshots small and focused
- Distinctive: line 37
Use React Testing Library over Enzyme for testing components
- Distinctive: line 38
Test user behavior and component accessibility
- Very specific: line 40
Use userEvent over fireEvent for more realistic user interactions
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Use when
- Writing or reviewing Jest tests for JS/TS code
- Setting up mocks, spies, or snapshot tests
Test 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)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

