For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt, and this page is available as Markdown at https://rstest.rs/guide/start/quick-start.md.
close
  • English
  • Quick start

    Online examples

    You can try Rstest online without any setup by using the following examples:

    Setup environment

    Before getting started, install Node.js 20.19.0 or later in the 20.x line, or 22.12.0 or later (^20.19.0 || >=22.12.0). We recommend an LTS version.

    Check the current Node.js version with the following command:

    node -v

    If you do not have Node.js installed in your current environment, or the installed version is too low, you can use nvm or fnm to install it:

    # Install Node.js LTS
    nvm install --lts
    # Switch to Node.js LTS
    nvm use --lts

    Using Rstest

    Agent prompt

    If you are using a coding agent, copy the following prompt to set up Rstest automatically (for migrating from Jest, Vitest, or Playwright Test, or installing Agent Skills, see the AI guide):

    For your Agent
    Set up Rstest

    Copy this prompt and send it to your coding agent.

    Manual installation

    Install @rstest/core as a dev dependency:

    npm
    yarn
    pnpm
    bun
    deno
    npm add @rstest/core -D

    Add a test script in package.json:

    package.json
    {
      "scripts": {
        "test": "rstest"
      }
    }

    Run tests with npm run test, yarn test, pnpm test, or directly with npx rstest.

    Rstest provides watch, run, and list commands; see CLI Tools for all commands and options.

    Writing tests

    Create a source file and a matching test file (or use in-source tests, similar to Rust tests):

    src/index.ts
    export const sayHi = () => 'hi';
    test/index.test.ts
    import { expect, test } from '@rstest/core';
    import { sayHi } from '../src/index';
    
    test('should sayHi correctly', () => {
      expect(sayHi()).toBe('hi');
    });

    Run the test command configured in Using Rstest. Rstest outputs:

     ✓ test/index.test.ts (1)
    
     Test Files 1 passed
          Tests 1 passed
       Duration 140 ms (build 17 ms, tests 123 ms)

    Type checking

    Rstest transforms TypeScript so tests can run, but does not check types. A passing test run does not mean the project has no type errors.

    Run your project's type check separately. For a project with TypeScript and a tsconfig.json, you can add a script:

    package.json
    {
      "scripts": {
        "test": "rstest",
        "typecheck": "tsc --noEmit"
      }
    }

    Run both test and typecheck in CI to check runtime behavior and types.

    Next steps

    If you want to see complete project structures, refer to these common examples:

    • node: Node.js testing and coverage collection.
    • react: React component, hook, and SSR tests with happy-dom.
    • vue: Vue component and SSR testing.
    • browser-react: React component testing in Browser Mode.

    For more examples, see Rstest examples.