frontend-unit-testing
Write comprehensive, behaviour-driven unit tests for Gradio frontend Svelte components using Vitest browser mode, Playwright, and the @self/tootils test utilities.
Оригинален текст · няма потвърден превод на българскиПърво прочетете инструкцията.
Файлът се зарежда от посочения източник само по ваше действие. Можете да го прочетете тук, да го копирате или да го запазите като .md.
GitHub хранилище- Звезди на репото
- 42 885
- Лиценз
- Не е посочен. Проверете в репозитория.
- Последна проверка на записа
- Няма посочена дата
Добавете в своя инструмент.
Командата отваря избора на skills от репозитория. Прочетете файла и условията на автора преди изпълнение.
npx skills add gradio-app/gradioСтраницата копира текст. Не инсталира и не изпълнява нищо на устройството ви.
Откъс от SKILL.md
Началото на файла на автора, без превод.
Frontend Unit Testing Skill
You are an expert at writing unit tests for Gradio's Svelte frontend components. Follow these instructions precisely.
Core Principles (Non-Negotiable)
-
Test everything. Unit tests are cheap. Having too many is a problem we want to have. When in doubt, write the test. Multiple tests per feature/argument is fine and encouraged.
-
Test behaviour, not implementation. Never assert on implementation details like CSS class names, internal state, or DOM structure for its own sake. Instead, test observable behaviour.
- BAD: assert that an input has a
stepattribute set to5 - GOOD: type a value, click the increment button, and assert the value increased by
5 - BAD: assert that a container has class
hidden - GOOD: assert that the element is not visible with
toBeVisible()
- BAD: assert that an input has a
-
Test Gradio-specific functionality. Every component has
get_data,set_data, and dispatches events. These must be tested, including their interactions with props.set_data-> verify the DOM reflects the changeget_data-> verify it returns the current stateset_data->get_dataround-trips- User interaction ->
get_datareflects it - Events:
change,input,submit,blur,focus,clear,upload,select,custom_button_click, etc.
-
Real browser environment. Tests run in Vitest browser mode with a Playwright provider. This is a real browser, not jsdom. Do not mock or stub unless absolutely unavoidable (e.g.,
navigator.clipboard,MediaStream). If you must mock, explain why in a comment. -
Test sub-components in isolation when they have meaningful standalone logic (e.g., a utility function, a shared inner component). These tests are in addition to full
Index.svelteintegration tests. -
Never refactor production code for testability without explicit user approval. If a refactor would help, recommend it and wait for a go-ahead.
-
Visual-only props get
test.todoplaceholders. If a prop or argument results in a purely visual change (colours, spacing, fonts, border styles, shadows, etc.) that cannot be meaningfully asserted with behavioural queries, do NOT skip it silently. Instead:- Add a
test.todo("description")explaining that it needs a visual regression test - The description should state what prop/value is being tested and what the expected visual outcome is
- This ensures visual-only behaviour is tracked and not forgotten
- Add a