Class AssertionState

Check the test suite internal state

import { AssertionState } from "@std/internal";

const assertionState = new AssertionState();

Constructors

Accessors

  • get assertionCount(): undefined | number
  • Get the number that through expect.assertions api set.

    Returns undefined | number

    the number that through expect.assertions api set.

    import { AssertionState } from "@std/internal";

    const assertionState = new AssertionState();
    assertionState.assertionCount;
  • get assertionTriggeredCount(): number
  • Get a certain number that assertions were called before.

    Returns number

    return a certain number that assertions were called before.

    import { AssertionState } from "@std/internal";

    const assertionState = new AssertionState();
    assertionState.assertionTriggeredCount;

Methods

  • Check Assertion called state, if #state.assertionCount is set to a number value, but #state.assertionTriggeredCount is less then it, then should throw an assertion error.

    Returns boolean

    a boolean value, that the test suite is satisfied with the check. If not, it should throw an AssertionError.

    import { AssertionState } from "@std/internal";

    const assertionState = new AssertionState();
    if (assertionState.checkAssertionCountSatisfied()) {
    // throw AssertionError("");
    }
  • Check Assertion internal state, if #state.assertionCheck is set true, but #state.assertionTriggered is still false, then should throw an Assertion Error.

    Returns boolean

    a boolean value, that the test suite is satisfied with the check. If not, it should throw an AssertionError.

    import { AssertionState } from "@std/internal";

    const assertionState = new AssertionState();
    if (assertionState.checkAssertionErrorState()) {
    // throw AssertionError("");
    }
  • Reset all assertion state when every test suite function ran completely.

    Returns void

    import { AssertionState } from "@std/internal";

    const assertionState = new AssertionState();
    assertionState.resetAssertionState();
  • If expect.hasAssertions called, then through this method to update #state.assertionCheck value.

    Parameters

    • val: boolean

      Set #state.assertionCheck's value

    Returns void

    import { AssertionState } from "@std/internal";

    const assertionState = new AssertionState();
    assertionState.setAssertionCheck(true);
  • If expect.assertions called, then through this method to update #state.assertionCheck value.

    Parameters

    • num: number

      Set #state.assertionCount's value, for example if the value is set 2, that means you must have two assertion matchers call in your test suite.

    Returns void

    import { AssertionState } from "@std/internal";

    const assertionState = new AssertionState();
    assertionState.setAssertionCount(2);
  • If any matchers was called, #state.assertionTriggered will be set through this method.

    Parameters

    • val: boolean

      Set #state.assertionTriggered's value

    Returns void

    import { AssertionState } from "@std/internal";

    const assertionState = new AssertionState();
    assertionState.setAssertionTriggered(true);
  • If any matchers was called, #state.assertionTriggeredCount value will plus one internally.

    Returns void

    import { AssertionState } from "@std/internal";

    const assertionState = new AssertionState();
    assertionState.updateAssertionTriggerCount();