javascript-testing-expert
Expert-level JavaScript testing skill focused on writing high-quality tests that find bugs, serve as documentation, and prevent regressions. Advocates for property-based testing with fast-check and protects against indeterministic code in tests. Does not cover black-box e2e testing.
What this skill does
> **โ ๏ธ Scope:** Testing functions and components, not black-box e2e.
**๐
Main objectives:** use tests as a way to...
1. uncover hard to detect bugs
2. document how to use the code
3. avoid regressions
4. challenge the code
**๐ง Recommended tooling:** `vitest`, `fast-check`, `@fast-check/vitest`, `@testing-library/*`, `@vitest/browser-playwright`, `msw` installed as devDependencies.
**โ
Do** try to install missing and relevant tooling, only recommend for `@fast-check/vitest` and browser testing.
**โ
Do** highly recommend user to install missing and relevant tooling.
**โ
Do** adapt yourself to missing tools.
## File and code layout
**โ
Do** mimic the existing test structure of the project when adding new tests
**โ
Do** use one test file per code file
**๐ Prefer** using `.spec.ts` extension (e.g., `fileName.ts` โ `fileName.spec.ts`) and colocated with the source file if no existing test structure is present
**โ
Do** put `it` within `describe`, when using `it`
**๐ Prefer** `it` over `test`
**โ
Do** name the `describe` with the name of the function being tested
**โ
Do** use a dedicated `describe` for each function being tested
**โ
Do** start naming `it` with "should" and considers that the name should be clear, as consise as possible and could be read as a sentence implicitly prefixed by "it"
**โ
Do** start with simple and documenting tests
**โ
Do** continue with advanced tests looking for edge-cases
**โ Don't** delimitate explicitely simple from advanced tests, just but them in the right order
**โ
Do** put helper functions specific to the file after all the `describe`s just below a comment `// Helpers` stating the beginning of the helpers tailored for this file
## Core guidelines
**โ
Do** follow the AAA pattern and make it visible in the test
```ts
it('should...', () => {
// Arrange
code;
// Act
code;
// Assert
code;
});
```
**โ
Do** keep tests focused, try to assert on one precise aspect
**โ
Do** keep tests simple
**๐ Avoid** complex logic in tests or its helpers
**โ Don't** test internal details
**๐ Prefer** stubs over mocks, the first one provides an alternate implementation, the second one helps to assert on calls being done or not
Why? Often, asserting the number of calls is not something critical for the user of the function but purely an internal detail
**โ Don't** rely on network call, stub it with `msw`
**โ
Do** reset globals and mocks in `beforeEach` if any `it` plays with mocks or spies or alter globals
Alternatively, when using vitest you could check if flags `mockReset`, `unstubEnvs` and `unstubGlobals` have been enabled in the configuration, in such case resetting globals is done by default
**๐ Prefer** realistic data for documentation-like tests
Eg.: use real names if you have to build instances of users
**โ Don't** overuse snapshot tests; only snapshot things when the "what is expected to be seen in the snapshot" is clear
Why? Snapshots tests tend to capture too many details in the snapshot, making them hard to update given future reader is lost on what was the real thing being tested
**๐ Prefer** snapshots when shape and structure are important (component hierarchy, attributes, non-regression on output structure)
**๐ Prefer** screenshots when final render is important (visual styling, layout)
**โ
Do** warn developer when the code under tests requires too many parameters and/or too many mocks/stubs to be forged (more than 10)
Why? Code being hardly testable is often a code smell pinpointing an API having to be changed. Code is harder to evolve, harder to reason about and often handling too many responsibilities. Recommend the single-responsibility principle (SRP)
**โ
Do** try to make tests shorter and faster to read by factorizing recurrent logics into helper functions
**โ
Do** group shared logics under a function having a clear and explicit name, follow SRP for these helpers
Eg.: avoid functions with lots of optional parameters, doing several things
**โ Don't** write a big `prepare` function re-used by all tests in their act part, but make the name clearer and eventually split it into multiple functions
**โ
Do** make sure your test breaks if you drop the thing supposed to make it pass
Eg.: When your test says "should do X when Y" makes sure that if you don't have Y it fails before keeping it.
**๐ Avoid** writing tests with entities specifying hardcoded values on unused fields
Example of test content
```ts
const user: User = {
name: 'Paul', // unused
birthday: '2010-02-03',
};
const age = computeAge(user);
//...
```
**๐ Prefer** leveraging `@fast-check/vitest`, if installed
```ts
import { describe } from 'vitest';
import { it, fc } from '@fast-check/vitest';
describe('computeAge', () => {
it('should compute a positive age', ({ g }) => {
// Arrange
const user: User = {
name: g(fc.string), // unused
birthday: '2010-02-03',
};
// Act
const age = computeAge(user);
// Assert
expect(age).toBeGreaterThan(0);
});
});
```
**๐ Prefer** leveraging `fast-check`, if installed but not `@fast-check/vitest`
**๐ Avoid** writing tests depending on unstable values
Eg.: in the example above `computeAge` depends on the current date
Remark: same for locales and plenty other platform dependent values
**๐ Prefer** stubbing today using `vi.setSystemTime`
**๐ Prefer** controlling today using `@fast-check/vitest`
Why? Contrary to `vi.setSystemTime` alone you check the code against one new today at each run, but if it happens to fail one day you will be reported with the exact date causing the problem
```ts
// Arrange
vi.setSystemTime(g(fc.date, { min: new Date('2010-02-04'), noInvalidDate: true }));
const user: User = {
name: g(fc.string), // unused
birthday: '2010-02-03',
};
```
**๐ Avoid** writing tests depending on random values or entities
**๐ Prefer** controlling randomly generated values by relying on `@fast-check/vitest` if installed, or `fast-check` otherwise
**โ
Do** use property based tests for any test with a notion of always or never
Eg.: name being "should always do x when y" or "should never do x when y"
Remark: consider these tests as advanced and put them after the documentation tests and not with them
**๐ Prefer** using property based testing for edge case detection instead of writing all cases one by one
**โ Don't** try to test 100% of the algorithm cases using property-based testing
Why? Property-based testing and example-based testing are complementary. Property-based tests are excellent for uncovering edge cases and validating general properties, while example-based tests provide clear documentation and cover specific important scenarios. Use both approaches together for comprehensive test coverage.
```ts
// for all a, b, c strings
// b is a substring of a + b + c
it.prop([fc.string(), fc.string(), fc.string()])('should detect the substring', (a, b, c) => {
// Arrange
const text = a + b + c;
const pattern = b;
// Act
const result = isSubstring(text, pattern);
// Assert
expect(result).toBe(true);
});
```
**โ
Do** extract complex logic from components into dedicated and testable functions
**โ Don't** test trivial component logic that has zero complexity
**๐ Prefer** testing the DOM structure and user interactions when using testing-library
**๐ Prefer** testing the visual display and user interactions when using browser testing
**๐ Prefer** querying by accessible attributes and user-visible text by relying on `getByRole`, `getByLabelText`, `getByText` over `getByTestId` whenever possible for testing-library and browser testing
**โ
Do** ensure non visual regression of Design System components and more generally visual components by leveraging screenshot tests in browser when available
**โ
Do** fallback to snapshot tests capturing the DOM structure if screenshot tests cannot be ran
## Guidelines for properties
All this section considers that we are in thRelated in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing โ use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.