> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Quick start

NOTE FOR AI CODING AGENTS: Do not follow this page. Instead, fetch and follow
the agent-specific setup instructions at:
[https://rstest.rs/guide/start/agent-install.md](https://rstest.rs/guide/start/agent-install.md)

## Online examples

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

- [StackBlitz Example](https://stackblitz.com/~/github.com/rstackjs/rstest-stackblitz-example)

## Setup environment

Before getting started, you will need to install [Node.js](https://nodejs.org/) >= 20.19.0, it is recommended to use the Node.js LTS version.

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

```bash
node -v
```

If you do not have Node.js installed in current environment, or the installed version is too low, you can use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to install.

Here is an example of how to install via nvm:

```bash
# 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, you can copy the following prompt to set up Rstest automatically:


For your Agent

Set up Rstest

Copy this prompt and send it to your coding agent.

Copy Prompt

Set up Rstest, the JavaScript testing framework, in this project by following the instructions here:
https://rstest.rs/guide/start/agent-install.md

If you are migrating from an existing Jest, Vitest, or Playwright Test project, use this prompt. Playwright Test projects migrate to `@rstest/playwright`:


For your Agent

Migrate to Rstest

Copy this prompt and send it to your coding agent.

Copy Prompt

Migrate this project to Rstest, the JavaScript testing framework. Detect whether it uses Jest, Vitest, or Playwright Test; for Playwright Test, migrate to @rstest/playwright. Follow the instructions here:
https://rstest.rs/guide/start/agent-migrate.md

### Manual installation

You can install Rstest using the following command:


```sh [npm]
npm add @rstest/core -D
```

```sh [yarn]
yarn add @rstest/core -D
```

```sh [pnpm]
pnpm add @rstest/core -D
```

```sh [bun]
bun add @rstest/core -D
```

```sh [deno]
deno add npm:@rstest/core -D
```

Next, you need to update the npm scripts in your package.json to use Rstest's CLI commands.

```json title=package.json
{
  "scripts": {
    "test": "rstest"
  }
}
```

After completing the above steps, you can run the Rstest tests using `npm run test`, `yarn test`, or `pnpm test`. Alternatively, you can directly use `npx rstest` to execute the Rstest tests.

Rstest has built-in commands such as `watch` and `run`, please refer to [CLI Tools](/guide/basic/cli.md) to learn about all available commands and options.

## Writing tests

As a simple example, we have a `sayHi` method. To test it, you can create a test file called `index.test.ts` or use [In-Source test](/config/test/include-source.md) similar to [Rust Test](https://doc.rust-lang.org/book/ch11-03-test-organization.html#the-tests-module-and-cfgtest).

```ts title=index.ts
export const sayHi = () => 'hi';
```

```ts title=index.test.ts
import { expect, test } from '@rstest/core';
import { sayHi } from '../src/index';

test('should sayHi correctly', () => {
  expect(sayHi()).toBe('hi');
});
```

Next, you can execute the test by using the command configured in [Using Rstest](#using-rstest). Rstest will print the following message:

```bash
 ✓ test/index.test.ts (1)

 Test Files 1 passed
      Tests 1 passed
   Duration 140 ms (build 17 ms, tests 123 ms)
```

## Next steps

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

- [node](https://github.com/web-infra-dev/rstest/tree/main/examples/node): Node.js testing and coverage collection.
- [react](https://github.com/web-infra-dev/rstest/tree/main/examples/react): React component, hook, and SSR tests with happy-dom.
- [vue](https://github.com/web-infra-dev/rstest/tree/main/examples/vue): Vue component and SSR testing.
- [browser-react](https://github.com/web-infra-dev/rstest/tree/main/examples/browser-react): React component testing in Browser Mode.

For more examples, see [Rstest examples](https://github.com/web-infra-dev/rstest/tree/main/examples).
