Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Expectation<Subject>

Expectation extends Box and adds support for verification (test cases).

Type parameters

  • Subject

Hierarchy

Implements

Index

Constructors

constructor

  • new Expectation(entity: any, negate?: undefined | false | true): Expectation

Properties

Protected entity

entity: any

Protected Optional negate

negate: undefined | false | true

Accessors

not

  • Boolean invert Expect the opposite of the expectation

    example

    // 2 + 2 !== 5 cyan.expect(2+2).not.toBe(5)

    Returns Expectation<Subject>

Methods

apply

  • Pass subject to function, yielding result.

    example
      // apply square
      cyan.wrap(2+2).apply((x) => x*x).unwrap() // 16

    Type parameters

    • U

    Parameters

    • fn: (t: Subject) => U

      Function to invoke

        • (t: Subject): U
        • Parameters

          • t: Subject

          Returns U

    Returns Expectation<U>

Private applyNegation

  • applyNegation(value: boolean): boolean

each

  • each<T, U>(fn: (t: T) => U): Box<U[]>
  • Pass elements of (array-like) subject to function, yielding result.

    example
      // apply square
      cyan.wrap([1,2,3]).each((x) => x*x).unwrap() // [2,4,6]

    Type parameters

    • T

    • U

    Parameters

    • fn: (t: T) => U

      Function to invoke

        • (t: T): U
        • Parameters

          • t: T

          Returns U

    Returns Box<U[]>

Protected errorDescription

  • errorDescription(expected: string, actual: string, claim: string): string
  • Parameters

    • expected: string
    • actual: string
    • claim: string

    Returns string

expect

Protected fail

  • fail(expected: any, actual: any, message: string): void
  • Parameters

    • expected: any
    • actual: any
    • message: string

    Returns void

filter

  • filter<T>(fn: (t: T) => boolean): Box<T[]>
  • Filter elements of (array-like) subject by predicate, yielding result.

    example
      // apply square
      cyan.wrap([1,2,3]).map((x) => x>2).unwrap() // [3]

    Type parameters

    • T

    Parameters

    • fn: (t: T) => boolean

      Function to invoke

        • (t: T): boolean
        • Parameters

          • t: T

          Returns boolean

    Returns Box<T[]>

glom

  • glom<T, P1>(prop1: P1): Expectation<A<T>[P1]>
  • glom<T, P1, P2>(prop1: P1, prop2: P2): Expectation<A<A<T>[P1]>[P2]>
  • glom<T, P1, P2, P3>(prop1: P1, prop2: P2, prop3: P3): Expectation<A<A<A<T>[P1]>[P2]>[P3]>
  • glom(...path: string[]): Expectation<any>

invokes

  • invokes<K, F, R>(key: K, ...args: any[]): Box<R>
  • Yield the result of calling a named method on the subject.

    arg

    key {string} the method name

    Type parameters

    • K: keyof Subject

    • F: Method<Subject, K>

    • R

    Parameters

    • key: K
    • Rest ...args: any[]

    Returns Box<R>

Protected isTruthy

  • isTruthy(value: boolean): boolean
  • Parameters

    • value: boolean

      the expression to verify

    Returns boolean

its

map

  • map<T, U>(fn: (t: T) => U): Box<U[]>
  • Pass elements of (array-like) subject to function, yielding result.

    example
      // apply square
      cyan.wrap([1,2,3]).map((x) => x*x).unwrap() // [2,4,6]

    Type parameters

    • T

    • U

    Parameters

    • fn: (t: T) => U

      Function to invoke

        • (t: T): U
        • Parameters

          • t: T

          Returns U

    Returns Box<U[]>

toBe

  • toBe(expected: Subject): void
  • Expect subject to deep-equal value.

    arg

    expected {Subject} the expected value

    example

    // 2 + 2 == 4 cyan.expect(2+2).toBe(4)

    Parameters

    • expected: Subject

    Returns void

unwrap

  • unwrap(): Subject
  • unwrap<Subject>(): never

wrap

  • wrap<T>(it: T): Box<T>
  • Yield an arbitrary subject.

    example
      // Open and shut
      cyan.wrap(2+2).unwrap() // => 4

    Type parameters

    • T

    Parameters

    • it: T

    Returns Box<T>

Static empty

  • empty(): Box<{}>
  • Build an empty box. Throw an error on yield if opened without wrapping anything else.

    Returns Box<{}>

Static with

  • with<U>(entity: U, negate?: undefined | false | true): Expectation<U>
  • with<U>(entity: Promise<U>, negate?: undefined | false | true): Expectation<U>
  • Assemble a new expectation, yielding the provided entity.

    Type parameters

    • U

    Parameters

    • entity: U

      the value to yield to the link

    • Optional negate: undefined | false | true

    Returns Expectation<U>

  • Type parameters

    • U

    Parameters

    • entity: Promise<U>
    • Optional negate: undefined | false | true

    Returns Expectation<U>

Generated using TypeDoc