close
logo
Rstest
Guide
Config
API
English
简体中文
Guide
Config
API
English
简体中文
logo
Rstest

Getting Started

Introduction
Quick start
Features

Basic

CLI
Configure Rstest
Filtering tests

Advanced

Debugging
Profiling

Migration

Migrating from jest
📝 Edit this page on GitHub
Previous PageIntroduction
Next PageFeatures

#Quick start

#Setup environment

Before getting started, you will need to install Node.js >= 18, it is recommended to use the Node.js LTS version.

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

node -v

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

Here is an example of how to install via nvm:

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

#Using Rstest

You can install Rstest using the following command:

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

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

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 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 similar to Rust Test.

index.ts
export const sayHi = () => 'hi';
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. Rstest will print the following message:

 ✓ test/index.test.ts (1)

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