agentleFS
jenrehjenreh/appkit/.claude/skills/reflex-testing-state/SKILL.md

reflex-testing-state

Skill4 starsChanged 5 months agoMITView on GitHub

Generates pytest unit tests for Reflex.dev state logic — event handlers, computed vars, substates, and mocked external dependencies. Use when the user asks to write, scaffold, or review tests for a Reflex State class. Do NOT use for Playwright

  • Installs packages

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

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

    Test it directly with pytest and pytest-asyncio.

    line 13

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “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

Testing Reflex State

Reflex State is a plain Python class — no browser or runtime needed. Test it directly with pytest and pytest-asyncio.

Setup

pip install pytest pytest-asyncio pytest-cov

pyproject.toml:

[tool.pytest.ini_options]
testpaths = ["tests/unit"]
asyncio_mode = "auto"
python_files = ["test_*.py"]

File layout

tests/unit/
├── conftest.py
├── test_base_state.py
└── test_project_state.py

Patterns

Base vars → test defaults directly Sync handlers → call on instance, assert result Async handlers → await, assert is_loading is False after Streaming handlers → consume with async for Computed vars → mutate base vars, assert property Substates → instantiate subclass independently External I/O → unittest.mock.patch at myapp.state.* Background tasks → patch __aenter__/__aexit__

See references/PATTERNS.md for full code examples. See references/FIXTURES.md for shared fixture setup.

Decision: which pattern to use?

Sync handler? → Test directly, no async Async handler? → Use await, check loading flag resets Handler bound to Radix UI component? → Add str AND list[str] test cases Handler calls API/DB? → Mock with AsyncMock, test both success and failure Background task (@rx.event(background=True))? → Patch context manager

Run

pytest tests/unit/ -v --cov=myapp/state --cov-report=term-missing
pytest tests/unit/test_project_state.py -v   # single module
pytest tests/unit/ -x                        # stop on first failure

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.