โšก
as-pect
  • โšกas-pect
  • ๐Ÿš€Getting Started
  • ๐Ÿ”งCLI Configuration
  • ๐Ÿ—๏ธAssemblyScript API
    • ๐Ÿ›๏ธTest Structure
    • ๐Ÿคทโ€โ™€๏ธ Expectations
      • ๐ŸŽญtoBe
      • ๐ŸคจtoStrictEqual
      • ๐ŸงฑtoBlockEqual
      • ๐Ÿ‘ฉโ€๐Ÿซ toBeTruthy and toBeFalsy
      • ๐Ÿ”ขtoBeNaN
      • ๐ŸšซtoBeNull
      • ๐ŸŒŒtoBeFinite
      • โšพtoThrow
      • โž•toBe(Greater|Less)Than
      • ๐Ÿ•ต๏ธโ€โ™€๏ธ toBeCloseTo
      • ๐Ÿ“toHaveLength
      • ๐ŸŽtoContain
      • ๐Ÿ“ฆtoContainEqual
      • โœ๏ธCustom Assertions
    • ๐ŸŽŸ๏ธTypes and Tooling
    • ๐Ÿช“Logging
    • ๐Ÿ‘ฉโ€๐Ÿ”ง RTrace and Memory Leaks
    • ๐Ÿ‘‰๐Ÿ‘ˆ Reflection
  • ๐ŸงถCore API
    • ๐ŸงชTestContext
    • ๐Ÿ‘ขBootstrap Tests Manually
    • ๐ŸŽ›๏ธTestGroup
    • โœ”๏ธTestResult
    • โœ๏ธReporters
      • ๐ŸฉณSummaryReporter
      • ๐Ÿ’ฌVerboseReporter
      • ๐ŸฅฝJSONReporter
      • ๐Ÿ—ƒ๏ธCSVReporter
Powered by GitBook
On this page

Was this helpful?

  1. AssemblyScript API
  2. ๐Ÿคทโ€โ™€๏ธ Expectations

toHaveLength

Check the length of a value

This comparison verifies the length of a given object. This includes Array, TypedArray, ArrayBuffer, and custom classes that have a length property.

class LengthExample {
  constructor(public length: i32 = 0) {}
}

const array = new Array<Vec3>(100);
const typedarray = new Uint8Array(42);
const buffer = new ArrayBuffer(29);
const custom = new LengthExample(50);

// Array<T> has a length
expect(array).toHaveLength(100);

// TypedArrays have a length
expect(typedarray).toHaveLength(42);

// ArrayBuffer uses byteLength
expect(buffer).toHaveLength(29);

// length is defined on LengthExample
expect(custom).toHaveLength(50);

If this method is used with anything other than a reference type, it will result in a compile time error.

Note: ArrayBufferclasses are tested using the byteLength property.

This method is safe to use with jest, with the exception of using ArrayBuffer type references.

Previous๐Ÿ•ต๏ธโ€โ™€๏ธ toBeCloseToNexttoContain

Last updated 5 years ago

Was this helpful?

๐Ÿ—๏ธ
๐Ÿ“