@hegeldev/hegel
    Preparing search index...

    Class Hegel

    A property-based test, configured with builder methods and then run with run (for an asynchronous test body) or runSync. hegel.test and hegel.testAsync are shorthands for a test that needs no more than settings.

    new hegel.Hegel((tc) => {
    tc.draw(gs.integers());
    })
    .settings({ testCases: 500 })
    .databaseKey("integers")
    .runSync();
    Index

    Constructors

    • Parameters

      • testFn: (tc: TestCase) => void | Promise<void>

      Returns Hegel

    Methods

    • Set the key the test's failures are stored under in the database, in place of the one derived from its location: its file, relative to the working directory, plus its name ("tests/a.test.ts::property"). A test function's name is its own, or for an anonymous one the name Vitest or Jest gives the running test, else the enclosing function's, else its line. When several hegel.test calls in one runner test or enclosing function borrow its name, they are numbered in the order their lines first run in the process, the first keeping the plain key and each later one carrying its number ("tests/a.test.ts::describe > test (2)"). Such a key does not depend on which other runner tests ran, but skipping an earlier call in the same runner test, adding one above it, or moving its line in a process that keeps Hegel loaded renumbers it; name the test function or set a key here to keep its saved failures. Where the runtime has no Error.captureStackTrace (Firefox) there is no call site to derive a location from: the key is the test function's name, and an anonymous test has none unless set here.

      Parameters

      • key: string

      Returns this

    • Add an explicit example: a test case run with the given values before any generated ones, each value served, in order, to one of the test's draws in place of a generated value. Explicit examples run in the Phase.Explicit phase. One that fails fails the test like a generated failing example does: it is reported, but not shrunk.

      Misusing an explicit example throws instead of being reported as a failing one: rejecting it with tc.assume or tc.reject (explicit test cases must not be rejected), leaving a value undrawn, making a draw it has no value for, or calling tc.drawSilent in it. tc.repeat runs its body once in an explicit example.

      Parameters

      • ...values: unknown[]

      Returns this

      new hegel.Hegel((tc) => {
      const xs = tc.draw(gs.arrays(gs.integers()));
      const n = tc.draw(gs.integers());
      // ...
      })
      .example([], 0)
      .example([1, 2, 3], -1)
      .runSync();
    • Add an explicit example whose values are served to draws by name: each key is the name a draw is reported under ("draw_1" for the test's first unnamed draw, or the name passed to TestCase.draw). See example.

      Parameters

      • values: Readonly<Record<string, unknown>>

      Returns this

      new hegel.Hegel((tc) => {
      const n = tc.draw(gs.integers(), "n");
      // ...
      })
      .namedExample({ n: 0 })
      .runSync();
    • Replay the failure that blob encodes instead of running the test normally: the blob a failure report prints, with the printBlob setting on, as how to reproduce it. Call it once for each failure to replay. A run that replays blobs generates nothing else, and throws a DidNotReproduceError when none of them fails any more.

      Parameters

      • blob: string

      Returns this

    • Run the test, awaiting an asynchronous test body.

      Returns Promise<void>

    • Run the test synchronously. The test body must not be asynchronous.

      Returns void

    • Set settings over the engine's resolved ones. Returns this for chaining.

      Parameters

      Returns this

    • Set where the test is defined, in place of the location derived from the call site. Inside Antithesis, the engine reports the run's verdict as an always assertion at this location.

      Parameters

      Returns this