Skip to content

Array Assertions

Dylan Parry edited this page Oct 5, 2016 · 10 revisions

Table of Contents

  1. toInclude
  2. toExclude
  3. toIncludeKey
  4. toExcludeKey
  5. toIncludeKeys
  6. toExcludeKeys
  7. toHaveLength

toInclude

expect(item: T[]).toInclude(value: T, message?: string): this;

Asserts that the array item includes value.

Outputs an optional message in case of a failed assertion.

Example

expect([1, 2, 3]).toInclude(2);

expect([1, 2, 3]).toInclude(4); // Assertion Error

Aliases

  • toContain

toExclude

expect(item: T[]).toExclude(value: T, message?: string): this;

Asserts that the array item does not include value.

Outputs an optional message in case of a failed assertion.

Example

expect([1, 2, 3]).toExclude(4);

expect([1, 2, 3]).toExclude(2); // Assertion Error

Aliases

  • toNotInclude
  • toNotContain

toIncludeKey

expect(item: T[]).toIncludeKey(key: number, message?: string): this;

Asserts that the array item includes the key.

Outputs an optional message in case of a failed assertion.

Example

expect([1, 2, 3]).toIncludeKey(0);

expect([1, 2, 3]).toIncludeKey(3); // Assertion Error

Aliases

  • toContainKey

toExcludeKey

expect(item: T[]).toExcludeKey(key: number, message?: string): this;

Asserts that the array item does not include the key.

Outputs an optional message in case of a failed assertion.

Example

expect([1, 2, 3]).toExcludeKey(3);

expect([1, 2, 3]).toExcludeKey(0); // Assertion Error

Aliases

  • toNotIncludeKey
  • toNotContainKey

toIncludeKeys

expect(item: T[]).toIncludeKeys(keys: number[], message?: string): this;

Asserts that the array item contains all of the keys.

Outputs an optional message in case of a failed assertion.

Example

expect([1, 2, 3]).toIncludeKeys([0, 1, 2]);

expect([1, 2, 3]).toIncludeKeys([3, 4]); // Assertion Error

Aliases

  • toContainKeys

toExcludeKeys

expect(item: T[]).toExcludeKeys(keys: number[], message?: string): this;

Asserts that the array item does not contain any of the keys.

Outputs an optional message in case of a failed assertion.

Example

expect([1, 2, 3]).toExcludeKeys([3, 4]);

expect([1, 2, 3]).toExcludeKeys([0, 1, 2]); // Assertion Error

Aliases

  • toNotIncludeKeys
  • toNotContainKeys

toHaveLength

expect(item: T[]).toHaveLength(value: number, message?: string): this;

Asserts that the number of items contained in the array item is equal to value.

Outputs an optional message in case of a failed assertion.

Example

expect([1, 2, 3]).toHaveLength(3);

expect([1, 2, 3]).toHaveLength(4); // Assertion Error