用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/razorpay/blade --skill write-unit-tests命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | write-unit-tests |
| description | This rule helps in writing and running unit tests for components of blade design system |
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