Logos DX
    Preparing search index...

    Function assert

    • Asserts that a value is true. Even though NodeJS has an assert builtin library, this aims to bring a single API for asserting across all environments.

      Parameters

      • test: unknown

        value that is coerced to true

      • Optionalmessage: string

        error message to display when test is false

      • OptionalErrorClass: ErrorConstructor

        error class to throw

      Returns void

      assert(true, 'this is true');
      assert(false, 'this is false');
      assert(() => true, 'this is true');
      assert(() => false, 'this is false');

      const SomeErrorClass = class extends Error {
      constructor(message: string) {
      super(message);
      }
      }


      const someFunc = () => {

      assert(true, 'this is true', SomeErrorClass);
      assert(false, 'this is false', SomeErrorClass);
      assert(() => true, 'this is true', SomeErrorClass);
      assert(() => false, 'this is false', SomeErrorClass);

      // some logic
      }

      someFunc();