Skip to content

DZakh-forks/rescript-vitest

 
 

Repository files navigation

rescript-vitest

npm npm downloads license

ReScript bindings to Vitest

Prerequisite

ReScript v10.1+ is required since v1.0.0. To use Js.Promise2 and async/await for tests.

ReScript v11 can be used with "uncurried": false

Config

Configure with plain vite.config.js.

You can use vite-plugin-rescript to build ReScript automatically before the test.

Usage

You can find examples on tests

Basic

open Vitest

describe("Hello, Vitest", () => {
  test("This is a test case", t => {
    // t is `expect` object for suite-wide assertions
    t->assertions(3)

    // Test using the `Expect` module
    expect(1 + 2)->Expect.toBe(3)

    // There are some nested modules for specific type
    expect([1, 2, 3])
    ->Expect.Array.toContain(2)

    expect("Hello, ReScript-Vitest!")
    ->Expect.String.toContain("ReScript")

  // You can specify timeout for a test suite
  }, ~timeout=2000)
})

In-source testing (experimental)

Vitest support in-source testing

// This if block can be removed from production code.
// You need to define `import.meta.vitest` to `undefined`
if Vitest.inSource {
  open Vitest
  open Vitest.InSource

  test("In-source testing", _ => {
    expect(1 + 2)->Expect.toBe(3)
  })
}

LICENCE

MIT

About

ReScript bindings to Vitest

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • ReScript 99.6%
  • JavaScript 0.4%