reflex-testing-state
jenreh/appkit/.claude/skills/reflex-testing-state/SKILL.md
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
Skill4 starsChanged 3 months ago
- Installs packages
What's in it
- Testing Reflex State
- Setup
- File layout
- Patterns
- Decision: which pattern to use?
- Run
--- name: reflex-testing-state description: > 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 integration tests or UI component rendering tests. --- # Testing Reflex State Reflex `State` is a plain Python class — no browser or runtime needed. Test it directly with `pytest` and `pytest-asyncio`. ## Setup ```bash pip install pytest pytest-asyncio pytest-cov ``` `pyproject.toml`: ```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](references/PATTERNS.md) for full code examples. See [references/FIXTURES.md](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 ```bash 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 ```
More agent context in jenreh/appkit
25 other files this repository gives its agents.
AGENTS.md
CLAUDE.md
llms.txt
Skill
- appkit-commons.claude/skills/appkit-commons/SKILL.md
- boost.claude/skills/boost/SKILL.md
- code-cleanup.claude/skills/code-cleanup/SKILL.md
- commit-msg.claude/skills/commit-msg/SKILL.md
- create-readme.claude/skills/create-readme/SKILL.md
- docker-multi-stage.claude/skills/docker-multi-stage/SKILL.md
- frontend-design.claude/skills/frontend-design/SKILL.md
- github-actions-cicd.claude/skills/github-actions-cicd/SKILL.md
- python-clean-code.claude/skills/python-clean-code/SKILL.md
- python-coding.claude/skills/python-coding/SKILL.md
- reflex-docs.claude/skills/reflex-docs/SKILL.md
- reflex-state-and-architecture.claude/skills/reflex-state-and-architecture/SKILL.md
- release.claude/skills/release/SKILL.md
- runic-migrate.claude/skills/runic-migrate/SKILL.md
- runic-ogm.claude/skills/runic-ogm/SKILL.md
- terraform-azure-verified-modules.claude/skills/terraform-azure-verified-modules/SKILL.md
- terraform-refactor-module.claude/skills/terraform-refactor-module/SKILL.md
- terraform-run-acceptance-tests.claude/skills/terraform-run-acceptance-tests/SKILL.md
- terraform-search-import.claude/skills/terraform-search-import/SKILL.md
- terraform-stacks.claude/skills/terraform-stacks/SKILL.md
- terraform-style-guide.claude/skills/terraform-style-guide/SKILL.md
- terraform-test.claude/skills/terraform-test/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
No reports yet. Be the first to say whether it worked.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

