ReScript Test Framework

8.0.0 · active · verified Tue Apr 21

rescript-test is a lightweight and performant test framework designed specifically for ReScript projects. Currently at version 8.0.0, it provides a native ReScript API for writing unit and integration tests, leveraging ReScript's type system for robust assertions. It integrates directly into the ReScript build pipeline, running compiled `.bs.js` files. The framework offers core testing primitives like `test`, `testAsync`, and flexible `assertion` functions, alongside utilities for setup/teardown and optional DOM simulation via JSDOM. It aims to provide a straightforward, type-safe testing experience tailored for the ReScript ecosystem, differentiating itself from general JavaScript test runners by its deep integration with ReScript's language features. It appears to be actively maintained, with updates typically correlating with ReScript compiler releases.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install `rescript-test`, configure `bsconfig.json`, write a basic ReScript test file with custom assertions, and execute it using the `retest` CLI.

yarn add --dev rescript-test

# Add to bsconfig.json:
# {
#   "bs-dev-dependencies": [
#     "rescript-test"
#   ]
# }

# Create test/MyTest.res
// test/MyTest.res
open Test

let intEqual = (~message=?, a: int, b: int) =>
  assertion(~message?, ~operator="intEqual", (a, b) => a === b, a, b)

test("Basic integer equality", () => {
  let actual = 1 + 1
  let expected = 2
  intEqual(~message="1 + 1 should be 2", actual, expected)
})

test("Async operation test", () => {
  // In a real scenario, this would involve a Promise or callback
  // For simplicity, showing a synchronous pass.
  pass()
})

# Run the tests
npx retest 'test/**/*.bs.js'

view raw JSON →