xstate-testing

Test XState v5 state machines with Vitest or Jest.

Updated Feb 12, 2026
One-click install
npx skills add https://github.com/IlyaGulya/claude-marketplace --skill xstate-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: xstate-testing
Source: https://github.com/IlyaGulya/claude-marketplace/tree/main/plugins/xstate/skills/xstate-testing
Command: npx skills add https://github.com/IlyaGulya/claude-marketplace --skill xstate-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides comprehensive strategies and patterns for effectively testing XState v5 state machines, ensuring the reliability and correctness of your application's state logic.

Core Features & Use Cases

  • Actor Testing: Verify machine behavior by creating actors, sending events, and asserting snapshots.
  • Pure Transition Testing: Test state transitions in isolation without creating actors, using transition() and initialTransition().
  • Mocking: Utilize .provide() to mock actions, actors, and guards for controlled testing scenarios.
  • Async Testing: Handle asynchronous operations with waitFor, toPromise, and promise resolution patterns.
  • Use Case: When developing a complex user authentication flow with XState, use this Skill to write robust tests that cover successful logins, error states, and session timeouts.

Quick Start

Use the xstate-testing skill to write unit tests for your XState v5 machines, focusing on behavior and transitions.

Frequently Asked Questions about xstate-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test XState v5 state machines with Vitest or Jest?

You test XState v5 machines by creating actors, sending events, and asserting snapshots using Vitest or Jest. This approach focuses on verifying actual behavior and transitions rather than internal configuration structure.

What is the best way to test pure state transitions in isolation?

Testing pure state transitions in isolation uses the `transition()` and `initialTransition()` functions to verify specific state changes directly, avoiding the overhead of instantiating full actors.

How do I mock actions, actors, and guards in XState v5 tests?

You mock actions, actors, and guards in XState v5 tests using the `.provide()` method to inject controlled implementations, isolating machine logic to ensure reliable and deterministic testing scenarios.

How do I handle asynchronous operations when testing XState actors?

Handle asynchronous operations in XState actor tests using `waitFor`, `toPromise`, and promise resolution patterns to verify async behavior like successful logins, error states, or session timeouts.

Can I test authentication flows by mocking actors with provide()?

Yes, you can test complex user authentication flows by mocking actors with `.provide()` to write robust tests covering successful logins, error states, and session timeouts.