write-unit-tests
Skill658 starsChanged 4 months agoMITView on GitHub
This rule helps in writing and running unit tests for components of blade design system
We split this skill into the rules it gives an agent
21 rules. 0 are common, 12 are distinctive, and 9 are very specific to this project.
0
Common
Most of the 10 edited versions we read keep these.
12
Distinctive
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
When component is interactive, you test its core functionality
- Distinctive: line 11
Before writing tests, you discuss which tests you're planning to write and only write tests post confirmation
- Very specific: line 19
Create tests in a __tests__ directory within the component folder
- Very specific: line 20
Use .web.test.tsx for web-specific tests and .ssr.test.tsx for server-side rendering tests
- Very specific: line 21
Follow the naming pattern: ComponentName.web.test.tsx and ComponentName.ssr.test.tsx
- Distinctive: line 25
Always start by examining existing test patterns (e.g., Box component tests) to understand established conventions
- Very specific: line 26
Use renderWithTheme for web tests and renderWithSSR for SSR tests
- Very specific: line 28
Import testing utilities from ~utils/testing/
- Very specific: line 40
Always prefer getByRole over anything else wherever possible
- Very specific: line 41
Use testID props for precise element targeting in other cases where getByRole is not possible
- Distinctive: line 45
Keep test cases focused and well-named with clear descriptions
- Distinctive: line 46
Avoid writing tests that can get flaky
- Very specific: line 47
Prefer toMatchSnapshot over toMatchInlineSnapshot especially in complex snapshots
- Distinctive: line 48
Avoid unnecessary repeatitive tests.
- Distinctive: line 52
Test different orientations, alignments, and layout configurations
- Distinctive: line 60
When testing computed styles, use specific pixel values that match design tokens
- Distinctive: line 62
Test both presence and absence of styling conditions
- Distinctive: line 66
Use this pattern for triggering any events
- Distinctive: line 78
Test the core Logic
- Distinctive: line 79
If there is any logic that is too complex or too flaky for unit tests, ignore it and suggest user to write integration test instead
- Very specific: line 134
Run test using following command from packages/blade directory
“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
You work in a design system team of Razorpay and you're good at writing unit tests. You make sure to cover all important scenarios in tests while also ensuring that you don't write too many unnecessary tests.
- You refer to existing tests for formats and inspirations. Refer to atleast 2 similar complexity components tests
- You refer to story docs of that component for references on realisitic examples to test
- When component is interactive, you test its core functionality
- Before writing tests, you discuss which tests you're planning to write and only write tests post confirmation
- You don't write
ComponentName.native.test.tsxtests since that is not maintained anymore - Whenever you're unsure about some practice, just ask for confirmation
Blade Component Testing Guidelines
Test File Structure
- Create tests in a
__tests__directory within the component folder - Use
.web.test.tsxfor web-specific tests and.ssr.test.tsxfor server-side rendering tests - Follow the naming pattern:
ComponentName.web.test.tsxandComponentName.ssr.test.tsx
Testing Patterns
- Always start by examining existing test patterns (e.g., Box component tests) to understand established conventions
- Use
renderWithThemefor web tests andrenderWithSSRfor SSR tests - Include
assertAccessibletest to ensure components meet accessibility standards - Import testing utilities from
~utils/testing/
Testing Utilities and Imports
import renderWithTheme from '~utils/testing/renderWithTheme.web';
import renderWithSSR from '~utils/testing/renderWithSSR';
import assertAccessible from '~utils/testing/assertAccessible.web';Element Selection Best Practices
- Always prefer
getByRoleover anything else wherever possible - Use
testIDprops for precise element targeting in other cases where getByRole is not possible
Code Style in Tests
- Keep test cases focused and well-named with clear descriptions
- Avoid writing tests that can get flaky
- Prefer
toMatchSnapshotovertoMatchInlineSnapshotespecially in complex snapshots - Avoid unnecessary repeatitive tests. Keep tests concise
Component Testing Patterns
- Test different orientations, alignments, and layout configurations
- For focussed testing of particular style, use
getComputedStyleinstead of adding snapshot for whole code - Include tests for conditional behavior that change the DOM structure heavily
Types of Tests
Styling/Layout Testing
- When testing computed styles, use specific pixel values that match design tokens
- Comment the expected values with their token references (e.g.,
// spacing.2 = 4px) - Test both presence and absence of styling conditions
Functional / Logic Testing
Use this pattern for triggering any events
import userEvents from '@testing-library/user-event'; const user = userEvents.setup(); // ...render example // click / other events await user.click(getByRole('button', { name: 'Toggle Show' }));- Test the core Logic
- If there is any logic that is too complex or too flaky for unit tests, ignore it and suggest user to write integration test instead
Import Organization
// Component imports
import { ComponentName, SubComponent } from '../index';
// Testing utilities
import renderWithTheme from '~utils/testing/renderWithTheme.web';
import assertAccessible from '~utils/testing/assertAccessible.web';
// Blade components used in tests
import { Icon, Avatar, Badge, Amount } from '~components/...';Test Structure Template
describe('<ComponentName />', () => {
it('should render simple ComponentName', () => {
// Basic rendering test with snapshot
});
it('should render ComponentName with different complex configurations', () => {
// Test various prop combinations
});
// Test for any hacky implementations that we've added while writing code that are likely break or not intuitive
it('should test for any hacky implementations', () => {
// Test conditional behavior with actual assertions
});
// test for import styling scenario
it('should render the important style', () => {
// Test for 2 most important styles using getComputedStyle
});
// test for core functionality (ignore if component is non-interactive)
it('should render ComponentName with different complex configurations', () => {
// Test various prop combinations
});
it('should accept testID', () => {
// Test testID prop support
});
it('should not have accessibility violations', async () => {
// accessibility violation test
await assertAccessible(container);
});
});Running the test
Run test using following command from packages/blade directory
yarn test:react ComponentNameOther versions11 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 11
- tldraw/tldraw★ 51ksame name
- CrowdDotDev/crowd.dev★ 3.4ksame name
- igorescodro/alkaa★ 1.6ksame name
- stripe/stripe-android★ 1.6ksame name
- Endava/BEEQ★ 162same name
- emaraschio/cursor-commands★ 9same name
- kennguyen887/agent-foundation★ 1same name
- cmnemoi/skills★ 0same name
- drewdoebereiner/write-unit-tests★ 0same name
- gologo13/agent-skills★ 0same name
1 more not listed
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.
Used alongsideProjects with it also use write-e2e-tests.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
igorescodroSkillwrite-e2e-tests
Use when writing or modifying end-to-end tests in the Alkaa project — triggers on tasks like "add an E2E test", "write a flow test", "test this feature end-to-end", "add a test to shared module", or "cover this user journey with a test".
Also in 3 projects that use this
In this repository19 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/agent-base-directory.mdcCursor rule
- .cursor/rules/orchestrator-guardrails.mdcCursor rule
- .cursor/rules/svelte-migration.mdcCursor rule
- check-component-readinessSkill
- code-reviewSkill
- create-prSkill
- get-agentic-blade-metricsSkill
- heal-prSkill
- migrate-to-rnSkill
- migrate-to-svelteSkill
- perform-task-end-to-endSkill
- resolve-commentsSkill
- review-prSkill
- update-componentSkill
- verify-with-browserSkill
- write-api-decisionSkill
- write-biweekly-announcementSkill
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.

