agentleFS
CloudflareKnown publishercloudflare/realtimekit-ui/.agents/skills/writing-tests/SKILL.md

writing-tests

Skill76 starsChanged 6 days agoApache-2.0View on GitHub

Use when writing or fixing realtimekit-ui Stencil/Jest specs, e2e tests, and fixtures after the developer confirms the code works and allows tests. Check visible component behavior and exported helpers without mocking the code under test.

52 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use reviewing-code, running-tests and 9 more.

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.
  • ZayZay1nonlySkill

    reviewing-code

    Provides structured code review with prioritized feedback. Use when reviewing PRs, analyzing code quality, checking for bugs, or auditing changes. Triggers on "review this", "check this code", PR reviews, or code quality questions.

    Also in 5 projects that use this

  • OpenAISkill

    running-tests

    Guide for running tests in the openai-dotnet repository. Use this when asked to run, debug, or validate tests, or when writing new tests. Explains test modes (Playback, Record, Live), how to identify recorded vs non-recorded tests, environment variable configuration, and what to do when recordings are missing or stale.

    Also in 4 projects that use this

  • JetBrainsSkill

    commits

    Read before each commit, amend or reword: the subject SafePush accepts and the body.

    Also in 3 projects that use this

  • BlockSkill

    debugging

    Debugging guidelines and best practices

    Also in 5 projects that use this

  • sahinSkill

    execute

    Also in 3 projects that use this

  • MicrosoftSkill

    council

    Convene the persona panel — six orthogonal review lenses — on a target. Cold independent fan-out, debate-to-consensus, synthesized verdict with recorded dissent and a roster manifest.

    Also in 4 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

19 rules. 0 are common, 11 are distinctive, and 8 are very specific to this project.

  • 0

    Common

    Most of the 52 edited versions we read keep these.

  • 11

    Distinctive

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Write tests only after the developer confirms the code works (see code-first-workflow).

    line 8
  2. Distinctive:

    If the repo has its own test setup skill or notes (commands, mock folders), read them first.

    line 12
  3. Very specific:

    Use Stencil's Jest runner and @stencil/core/testing for component specs.

    line 14
  4. Very specific:

    Check what an app can see: shadow DOM, props, emitted event detail, or a returned UIConfig.

    line 19
  5. Distinctive:

    Keep UI Kit render logic, state updates, and shared helpers real when those are the code under test.

    line 21
  6. Distinctive:

    Search nearby specs for usable setup before you create a new fixture.

    line 31
  7. Distinctive:

    Use an existing shared helper if it fits.

    line 32
  8. Very specific:

    Use jest.fn() for an SDK method the component calls.

    line 33
  9. Distinctive:

    If the same setup repeats across several specs, extract it to a shared helper and check its existing users.

    line 34
  10. Distinctive:

    Write one test for each behaviour on that list.

    line 48
  11. Very specific:

    Run the relevant specs once.

    line 49
  12. Distinctive:

    Test data has the same shape as real data.

    line 69
  13. Very specific:

    Follow strict-naming in test code as well.

    line 70
  14. Distinctive:

    If mock setup is more than half of a test, you are mocking at the wrong level.

    line 71
  15. Distinctive:

    Run the tests in single-run mode, not watch mode.

    line 75
  16. Distinctive:

    Check that the assertion would catch the behavior it describes.

    line 76
  17. Distinctive:

    Run the other tests of the area you touched.

    line 77
  18. Very specific:

    When you must ask the developer, follow "Asking questions" in code-first-workflow: all questions in one message, each with your suggestion.

    line 84
  19. Very specific:

    Use the "Final report" of code-first-workflow.

    line 96

“Common” is measured: kept by at least 6 in 10 of the 52 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Writing tests

Write tests only after the developer confirms the code works (see code-first-workflow). Do not add tests for a docs-only edit.

Goal: every new or changed line and branch runs inside a test, and the test checks what that line does.

If the repo has its own test setup skill or notes (commands, mock folders), read them first.

Use Stencil's Jest runner and @stencil/core/testing for component specs. Read realtimekit-test-setup for commands.

1. Test the real code

  • Render the real component with newSpecPage, or call the real exported helper.
  • Check what an app can see: shadow DOM, props, emitted event detail, or a returned UIConfig.
  • Mock boundaries outside the UI Kit when needed: the meeting SDK object, browser/device APIs, timers, and network calls.
  • Keep UI Kit render logic, state updates, and shared helpers real when those are the code under test.

Reason: a mocked function is a function the test never runs. Its lines stay unverified even when the coverage number looks good.

When you add tests to an existing spec, keep the mock level that spec already uses, as long as the lines you are testing still run for real. Do not rewrite existing tests to move the mock level. If the existing level stops your lines from running, say so and ask.

2. Reuse setup where it helps

A small fixture local to one spec is fine. Share a mock or builder when several specs need it.

  1. Search nearby specs for usable setup before you create a new fixture.
  2. Use an existing shared helper if it fits. Do not change unrelated tests just to move mocks.
  3. Use jest.fn() for an SDK method the component calls. Keep the rest of the fake meeting as small as the component needs.
  4. If the same setup repeats across several specs, extract it to a shared helper and check its existing users.

Inside a spec file:

AllowedBelongs in the shared location
jest.fn() for a meeting method called by the componentReplacing the component or helper being tested with a mock
jest.spyOn() on an edge such as a browser APIMocking the UI Kit behavior whose result you need to check
A local createMeeting() fixture in one specRepeating the same large setup across many specs
jest.useFakeTimers() when timing mattersAdvancing timers without asserting the visible effect

3. Cover every new line, honestly

  1. List the changed behaviors and branches from the diff: each visible state, prop default, event, or helper result. Include failure paths when they apply.
  2. Write one test for each behaviour on that list. Include the failure paths.
  3. Run the relevant specs once. Use the core test:coverage script when coverage is needed; do not use the watch-mode test:spec script for this.
  4. For each uncovered new line, add a test. If no real input can reach the line, do not force it. Tell the developer the line may be dead code.

These tricks are not allowed:

  • Coverage-ignore comments such as /* istanbul ignore next */.
  • test.skip, test.only, test.todo, or commented-out tests left in the file.
  • A test with no assertion, or one that only checks "does not throw", written to run lines.
  • Checking only that a mock was called when the real effect can be checked.
  • Assertions about what the mock itself does.
  • Copying the production logic into the test to compute the expected value. Write the expected value by hand.
  • Inputs that can never occur in the real flow.
  • Reaching private state with as any when a public path exists.
  • Making a failing test pass by weakening its assertion or deleting it.
  • Changing production code only to make a test easier (test-only methods, exporting private things). Ask first.

4. Write clear tests

  • The test name is the UI scenario in plain words: shows the setup screen when showSetupScreen is true.
  • One behaviour per test.
  • Test data has the same shape as real data. Use complete payloads.
  • Follow strict-naming in test code as well.
  • If mock setup is more than half of a test, you are mocking at the wrong level. Move the mock closer to the edge.

5. Prove the tests work

  1. Run the tests in single-run mode, not watch mode. Read the full output.
  2. Check that the assertion would catch the behavior it describes. Prefer a clear DOM, event, or config assertion over changing production code just to force a failure.
  3. Run the other tests of the area you touched. Report failures you did not cause. Do not hide them.
  4. Fix type and lint errors in the test files.

A test that does not check a visible result needs a stronger assertion. Rewrite it.

6. When something is wrong

When you must ask the developer, follow "Asking questions" in code-first-workflow: all questions in one message, each with your suggestion.

SituationWhat to do
A new test failsFind which side is wrong, the code or the test. If the test is wrong, fix the test.
The code you wrote for this task is wrong, or misses a caseFix the code, then the test. Tell the developer what you changed, why, and what to check again. Follow "When tests show that the code is wrong" in code-first-workflow. Never change the code only to make a test pass.
Code that is not part of this task looks like a bugDo not fix it. Do not write a test that expects the suspected bug. Flag it with file and line, the ways to fix it, and your suggestion.
A line can be reached, but only with a side effect that breaks the test runDo not force it. Report it.
One part of the task is blockedFinish the part that is not blocked. Then stop and ask about the blocked part.

Report

Use the "Final report" of code-first-workflow. Add this line to it:

Shared mocks added or changed: <list, or "none">

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.