.cursor/skills/write-unit-tests/SKILL.md
This rule helps in writing and running unit tests for components of blade design system
npx skillsauth add razorpay/blade write-unit-testsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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.
ComponentName.native.test.tsx tests since that is not maintained anymore__tests__ directory within the component folder.web.test.tsx for web-specific tests and .ssr.test.tsx for server-side rendering testsComponentName.web.test.tsx and ComponentName.ssr.test.tsxrenderWithTheme for web tests and renderWithSSR for SSR testsassertAccessible test to ensure components meet accessibility standards~utils/testing/import renderWithTheme from '~utils/testing/renderWithTheme.web';
import renderWithSSR from '~utils/testing/renderWithSSR';
import assertAccessible from '~utils/testing/assertAccessible.web';
getByRole over anything else wherever possibletestID props for precise element targeting in other cases where getByRole is not possibletoMatchSnapshot over toMatchInlineSnapshot especially in complex snapshotsgetComputedStyle instead of adding snapshot for whole code// spacing.2 = 4px)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
// 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/...';
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);
});
});
Run test using following command from packages/blade directory
yarn test:react ComponentName
documentation
Generate bi-weekly announcement posts for Blade Design System updates by analyzing changelog entries from the past two weeks
development
This rule helps in writing API decisions for new components of blade design system
tools
Visually verify component changes in Storybook using the agent-browser CLI tool
development
Update an existing Blade component (web only) using Figma designs and knowledgebase documentation