@kayahr/assert
    Preparing search index...

    Function assertCloseTo

    • Asserts that the two values are recursively equal but the difference to assertEquals is that numbers are considered to be equal when they are close enough to each other (configurable by number of decimal digits to compare).

      Examples:

      assertCloseTo(10.351, 10.352, 2);
      assertCloseTo({ value: 1.999 }, { value: 1.9992, 3 });
      assertCloseTo([ 1, 2.1, 3 ], [ 1, 2.10001, 3 ], 3);

      Type Parameters

      • Actual

        The type of the actual value.

      • Expected

        The type of the expected value.

      Parameters

      • actual: Actual

        The actual value to compare.

      • expected: Expected

        The expected value to compare with.

      • precision: number = 2

        The number of decimal digits to round numbers to before comparing. Defaults to 2.

      • Optionalreason: string

        Optional reason added to exception message when assertion fails.

      Returns asserts actual is Actual & Expected

      AssertionError when values are not close enough.