@types/assert-plus

  • Version 1.0.5
  • Published
  • 15.7 kB
  • 1 dependency
  • MIT license

Install

npm i @types/assert-plus
yarn add @types/assert-plus
pnpm add @types/assert-plus

Overview

TypeScript definitions for assert-plus

Index

Functions

function array

array: (arr: any[], message?: string) => asserts arr is any[];

    function arrayOfArray

    arrayOfArray: (arr: any[][], message?: string) => asserts arr is any[][];

      function arrayOfBool

      arrayOfBool: (arr: boolean[], message?: string) => asserts arr is boolean[];

        function arrayOfBuffer

        arrayOfBuffer: (arr: Buffer[], message?: string) => asserts arr is Buffer[];

          function arrayOfDate

          arrayOfDate: (arr: Date[], message?: string) => asserts arr is Date[];

            function arrayOfFinite

            arrayOfFinite: (arr: number[], message?: string) => asserts arr is number[];

              function arrayOfFunc

              arrayOfFunc: (arr: Func[], message?: string) => asserts arr is Func[];

                function arrayOfNumber

                arrayOfNumber: (arr: number[], message?: string) => asserts arr is number[];

                  function arrayOfObject

                  arrayOfObject: <T extends object = any>(
                  arr: T[],
                  message?: string
                  ) => asserts arr is T[];

                    function arrayOfRegexp

                    arrayOfRegexp: (arr: RegExp[], message?: string) => asserts arr is RegExp[];

                      function arrayOfStream

                      arrayOfStream: (arr: Stream[], message?: string) => asserts arr is Stream[];

                        function arrayOfString

                        arrayOfString: (arr: string[], message?: string) => asserts arr is string[];

                          function arrayOfUuid

                          arrayOfUuid: (arr: string[], message?: string) => asserts arr is string[];

                            function AssertionError

                            AssertionError: (options: any, message?: string) => void;

                              function bool

                              bool: (bool: boolean, message?: string) => asserts bool is boolean;

                                function buffer

                                buffer: (buffer: Buffer, message?: string) => asserts buffer is Buffer;

                                  function date

                                  date: (date: Date, message?: string) => asserts date is Date;

                                    function deepEqual

                                    deepEqual: <T>(actual: T, expected: T, message?: string) => void;
                                    • Tests for deep equality between the actual and expected parameters. Primitive values are compared with the equal comparison operator ( == ).

                                      Only enumerable "own" properties are considered. The deepEqual() implementation does not test object prototypes, attached symbols, or non-enumerable properties. This can lead to some potentially surprising results. For example, the following example does not throw an AssertionError because the properties on the Error object are non-enumerable:

                                      // WARNING: This does not throw an AssertionError!
                                      assert.deepEqual(Error('a'), Error('b'));

                                      "Deep" equality means that the enumerable "own" properties of child objects are evaluated also.

                                      If the values are not equal, an AssertionError is thrown with a message property set equal to the value of the message parameter. If the message parameter is undefined, a default error message is assigned.

                                    function doesNotThrow

                                    doesNotThrow: (block: any, error?: any, message?: string) => void;
                                    • Asserts that the function block does not throw an error. See assert.throws() for more details.

                                      When assert.doesNotThrow() is called, it will immediately call the block function.

                                      If an error is thrown and it is the same type as that specified by the error parameter, then an AssertionError is thrown. If the error is of a different type, or if the error parameter is undefined, the error is propagated back to the caller.

                                      The following, for instance, will throw the TypeError because there is no matching error type in the assertion:

                                      assert.doesNotThrow(
                                      () => {
                                      throw new TypeError('Wrong value');
                                      },
                                      SyntaxError
                                      );

                                      However, the following will result in an AssertionError with the message 'Got unwanted exception (TypeError)..':

                                      assert.doesNotThrow(
                                      () => {
                                      throw new TypeError('Wrong value');
                                      },
                                      TypeError
                                      );

                                      If an AssertionError is thrown and a value is provided for the message parameter, the value of message will be appended to the AssertionError message:

                                      assert.doesNotThrow(
                                      () => {
                                      throw new TypeError('Wrong value');
                                      },
                                      TypeError,
                                      'Whoops'
                                      );
                                      // Throws: AssertionError: Got unwanted exception (TypeError). Whoops

                                    function equal

                                    equal: (actual: any, expected: any, message?: string) => void;
                                    • Tests shallow, coercive equality between the actual and expected parameters using the equal comparison operator ( == ).

                                      const assert = require('assert');
                                      assert.equal(1, 1);
                                      // OK, 1 == 1
                                      assert.equal(1, '1');
                                      // OK, 1 == '1'
                                      assert.equal(1, 2);
                                      // AssertionError: 1 == 2
                                      assert.equal({a: {b: 1}}, {a: {b: 1}});
                                      //AssertionError: { a: { b: 1 } } == { a: { b: 1 } }

                                      If the values are not equal, an AssertionError is thrown with a message property set equal to the value of the message parameter. If the message parameter is undefined, a default error message is assigned.

                                    function fail

                                    fail: (actual: any, expected: any, message: any, operator: any) => void;
                                    • Throws an AssertionError. If message is falsy, the error message is set as the values of actual and expected separated by the provided operator. Otherwise, the error message is the value of message.

                                      const assert = require('assert');
                                      assert.fail(1, 2, undefined, '>');
                                      // AssertionError: 1 > 2
                                      assert.fail(1, 2, 'whoops', '>');
                                      // AssertionError: whoops

                                    function finite

                                    finite: (finite: number, message?: string) => asserts finite is number;

                                      function func

                                      func: (func: Func, message?: string) => asserts func is Func;

                                        function ifError

                                        ifError: (value: any) => void;
                                        • Throws value if value is truthy. This is useful when testing the error argument in callbacks.

                                          const assert = require('assert');
                                          assert.ifError(0);
                                          // OK
                                          assert.ifError(1);
                                          // Throws 1
                                          assert.ifError('error');
                                          // Throws 'error'
                                          assert.ifError(new Error());
                                          // Throws Error

                                        function notDeepEqual

                                        notDeepEqual: (actual: any, expected: any, message?: string) => void;
                                        • Tests for any deep inequality. Opposite of assert.deepEqual().

                                          const assert = require('assert');
                                          const obj1 = { a : { b : 1 } };
                                          const obj2 = { a : { b : 2 } };
                                          const obj3 = { a : { b : 1 } };
                                          const obj4 = Object.create(obj1);
                                          assert.notDeepEqual(obj1, obj1);
                                          // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
                                          assert.notDeepEqual(obj1, obj2);
                                          // OK, obj1 and obj2 are not deeply equal
                                          assert.notDeepEqual(obj1, obj3);
                                          // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
                                          assert.notDeepEqual(obj1, obj4);
                                          // OK, obj1 and obj2 are not deeply equal

                                          If the values are deeply equal, an AssertionError is thrown with a message property set equal to the value of the message parameter. If the message parameter is undefined, a default error message is assigned.

                                        function notEqual

                                        notEqual: (actual: any, expected: any, message?: string) => void;
                                        • Tests shallow, coercive inequality with the not equal comparison operator ( != ).

                                          const assert = require('assert');
                                          assert.notEqual(1, 2);
                                          // OK
                                          assert.notEqual(1, 1);
                                          // AssertionError: 1 != 1
                                          assert.notEqual(1, '1');
                                          // AssertionError: 1 != '1'

                                          If the values are equal, an AssertionError is thrown with a message property set equal to the value of the message parameter. If the message parameter is undefined, a default error message is assigned.

                                        function notStrictEqual

                                        notStrictEqual: (actual: any, expected: any, message?: string) => void;
                                        • Tests strict inequality as determined by the strict not equal operator ( !== ).

                                          const assert = require('assert');
                                          assert.notStrictEqual(1, 2);
                                          // OK
                                          assert.notStrictEqual(1, 1);
                                          // AssertionError: 1 !== 1
                                          assert.notStrictEqual(1, '1');
                                          // OK

                                          If the values are strictly equal, an AssertionError is thrown with a message property set equal to the value of the message parameter. If the message parameter is undefined, a default error message is assigned.

                                        function number

                                        number: (number: number, message?: string) => asserts number is number;

                                          function object

                                          object: <T extends object = any>(obj: T, message?: string) => asserts obj is T;

                                            function ok

                                            ok: (options: any, message?: string) => void;
                                            • Tests if value is truthy. It is equivalent to assert.equal(!!value, true, message).

                                              If value is not truthy, an AssertionError is thrown with a message property set equal to the value of the message parameter. If the message parameter is undefined, a default error message is assigned.

                                              const assert = require('assert');
                                              assert.ok(true);
                                              // OK
                                              assert.ok(1);
                                              // OK
                                              assert.ok(false);
                                              // throws "AssertionError: false == true"
                                              assert.ok(0);
                                              // throws "AssertionError: 0 == true"
                                              assert.ok(false, 'it\'s false');
                                              // throws "AssertionError: it's false"

                                            function optionalArray

                                            optionalArray: (
                                            arr: any[] | undefined,
                                            message?: string
                                            ) => asserts arr is any[];

                                              function optionalArrayOfArray

                                              optionalArrayOfArray: (
                                              arr: any[][] | undefined,
                                              message?: string
                                              ) => asserts arr is any[][];

                                                function optionalArrayOfBool

                                                optionalArrayOfBool: (
                                                arr: boolean[] | undefined,
                                                message?: string
                                                ) => asserts arr is boolean[];

                                                  function optionalArrayOfBuffer

                                                  optionalArrayOfBuffer: (
                                                  arr: Buffer[] | undefined,
                                                  message?: string
                                                  ) => asserts arr is Buffer[];

                                                    function optionalArrayOfDate

                                                    optionalArrayOfDate: (
                                                    arr: Date[] | undefined,
                                                    message?: string
                                                    ) => asserts arr is Date[];

                                                      function optionalArrayOfFinite

                                                      optionalArrayOfFinite: (
                                                      arr: number[] | undefined,
                                                      message?: string
                                                      ) => asserts arr is number[];

                                                        function optionalArrayOfFunc

                                                        optionalArrayOfFunc: (
                                                        arr: Func[] | undefined,
                                                        message?: string
                                                        ) => asserts arr is Func[];

                                                          function optionalArrayOfNumber

                                                          optionalArrayOfNumber: (
                                                          arr: number[] | undefined,
                                                          message?: string
                                                          ) => asserts arr is number[];

                                                            function optionalArrayOfObject

                                                            optionalArrayOfObject: <T extends object = any>(
                                                            arr: T[] | undefined,
                                                            message?: string
                                                            ) => asserts arr is T[];

                                                              function optionalArrayOfRegexp

                                                              optionalArrayOfRegexp: (
                                                              arr: RegExp[] | undefined,
                                                              message?: string
                                                              ) => asserts arr is RegExp[];

                                                                function optionalArrayOfStream

                                                                optionalArrayOfStream: (
                                                                arr: Stream[] | undefined,
                                                                message?: string
                                                                ) => asserts arr is Stream[];

                                                                  function optionalArrayOfString

                                                                  optionalArrayOfString: (
                                                                  arr: string[] | undefined,
                                                                  message?: string
                                                                  ) => asserts arr is string[];

                                                                    function optionalArrayOfUuid

                                                                    optionalArrayOfUuid: (
                                                                    arr: string[] | undefined,
                                                                    message?: string
                                                                    ) => asserts arr is string[];

                                                                      function optionalBool

                                                                      optionalBool: (
                                                                      bool: boolean | undefined,
                                                                      message?: string
                                                                      ) => asserts bool is boolean;

                                                                        function optionalBuffer

                                                                        optionalBuffer: (
                                                                        buffer: Buffer | undefined,
                                                                        message?: string
                                                                        ) => asserts buffer is any;

                                                                          function optionalDate

                                                                          optionalDate: (
                                                                          options: Date | undefined,
                                                                          message?: string
                                                                          ) => asserts options is Date;

                                                                            function optionalFinite

                                                                            optionalFinite: (
                                                                            options: number | undefined,
                                                                            message?: string
                                                                            ) => asserts options is number;

                                                                              function optionalFunc

                                                                              optionalFunc: (
                                                                              options: Func | undefined,
                                                                              message?: string
                                                                              ) => asserts options is Func;

                                                                                function optionalNumber

                                                                                optionalNumber: (
                                                                                options: number | undefined,
                                                                                message?: string
                                                                                ) => asserts options is number;

                                                                                  function optionalObject

                                                                                  optionalObject: <T extends object = any>(
                                                                                  options: T | undefined,
                                                                                  message?: string
                                                                                  ) => asserts options is T;

                                                                                    function optionalRegexp

                                                                                    optionalRegexp: (
                                                                                    options: RegExp | undefined,
                                                                                    message?: string
                                                                                    ) => asserts options is RegExp;

                                                                                      function optionalStream

                                                                                      optionalStream: (
                                                                                      options: Stream | undefined,
                                                                                      message?: string
                                                                                      ) => asserts options is any;

                                                                                        function optionalString

                                                                                        optionalString: (
                                                                                        options: string | undefined,
                                                                                        message?: string
                                                                                        ) => asserts options is string;

                                                                                          function optionalUuid

                                                                                          optionalUuid: (
                                                                                          options: string | undefined,
                                                                                          message?: string
                                                                                          ) => asserts options is string;

                                                                                            function regexp

                                                                                            regexp: (regexp: RegExp, message?: string) => asserts regexp is RegExp;

                                                                                              function stream

                                                                                              stream: (stream: Stream, message?: string) => asserts stream is Stream;

                                                                                                function strictEqual

                                                                                                strictEqual: <T>(actual: T, expected: T, message?: string) => void;
                                                                                                • Tests strict equality as determined by the strict equality operator ( === ).

                                                                                                  const assert = require('assert');
                                                                                                  assert.strictEqual(1, 2);
                                                                                                  // AssertionError: 1 === 2
                                                                                                  assert.strictEqual(1, 1);
                                                                                                  // OK
                                                                                                  assert.strictEqual(1, '1');
                                                                                                  // AssertionError: 1 === '1'

                                                                                                  If the values are not strictly equal, an AssertionError is thrown with a message property set equal to the value of the message parameter. If the message parameter is undefined, a default error message is assigned.

                                                                                                function string

                                                                                                string: (str: string, message?: string) => asserts str is string;

                                                                                                  function throws

                                                                                                  throws: (block: any, error?: any, message?: string) => void;

                                                                                                    function uuid

                                                                                                    uuid: (uuid: string, message?: string) => asserts uuid is string;

                                                                                                      Package Files (1)

                                                                                                      Dependencies (1)

                                                                                                      Dev Dependencies (0)

                                                                                                      No dev dependencies.

                                                                                                      Peer Dependencies (0)

                                                                                                      No peer dependencies.

                                                                                                      Badge

                                                                                                      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/assert-plus.

                                                                                                      • Markdown
                                                                                                        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/assert-plus)
                                                                                                      • HTML
                                                                                                        <a href="https://www.jsdocs.io/package/@types/assert-plus"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>