Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Expectation<Subject>

An Expectation asserts a claim on the subject.

example
  // 2 + 2 == 4
  cyr.expect(2+2).toBe(4)

  // 'hello world' matches /hello/
  cyr.expect("hello world").toMatch("hello")

Type parameters

  • Subject

Hierarchy

  • Expectation

Implements

Index

Constructors

constructor

Properties

Protected entity

entity: Subject

Private expectedValue

expectedValue: ExactValue | MatchValue

lenses

lenses: Lens[] = []

Accessors

actual

  • get actual(): Subject

expected

Methods

Private cmpEq

  • cmpEq(expected: any, actual: any): void

Private cmpMatch

  • cmpMatch(expected: string, actual: any): void

Private cmpMsg

  • cmpMsg(expected: any, actual: any, fnName: string, comment?: undefined | string): string
  • Parameters

    • expected: any
    • actual: any
    • fnName: string
    • Optional comment: undefined | string

    Returns string

Private fail

  • fail(expected: any, actual: any, fnName: string, comment?: undefined | string): void
  • Parameters

    • expected: any
    • actual: any
    • fnName: string
    • Optional comment: undefined | string

    Returns void

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>
  • Yield a nested property on the subject.

    example
     // Yield my.value
     cyr.wrap({ my: { value: 'here' }})
        .glom('my', 'value')
        .unwrap() // => 'here'
    
     // Yield by path
     cyr.wrap({ my: { value: 'here' }})
        .glom('my.value')
        .unwrap() // => 'here'

    Type parameters

    • T: Subject

    • P1: keyof A<T>

    Parameters

    • prop1: P1

    Returns Expectation<A<T>[P1]>

  • Type parameters

    • T: Subject

    • P1: keyof A<T>

    • P2: keyof A<A<T>[P1]>

    Parameters

    • prop1: P1
    • prop2: P2

    Returns Expectation<A<A<T>[P1]>[P2]>

  • Type parameters

    • T: Subject

    • P1: keyof A<T>

    • P2: keyof A<A<T>[P1]>

    • P3: keyof A<A<A<T>[P1]>[P2]>

    Parameters

    • prop1: P1
    • prop2: P2
    • prop3: P3

    Returns Expectation<A<A<A<T>[P1]>[P2]>[P3]>

  • Parameters

    • Rest ...path: string[]

    Returns Expectation<any>

invokes

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

    example
      // Invoke `my.fn` on the wrapped subject
      cyr.wrap({ my: { fn: () => 3 }}).expect('my').invokes('fn').toBe(3)

    Type parameters

    Parameters

    • key: K

      Method name

    • Rest ...args: any[]

      Argument list

    Returns Expectation<R>

its

  • Yield a named property on the subject.

    example
      // Pluck `my.value` from the wrapped subject
      cyr.wrap({ my: { value: 'here' }})
         .its('my').its('value')

    Type parameters

    • T: any

    • K: keyof Subject

    • U: Subject[K]

    • R: Promise<T> & U

    Parameters

    • key: K

      Method name

    Returns Expectation<T>

  • Type parameters

    • K: keyof Subject

    Parameters

    • key: K

    Returns Expectation<Subject[K]>

toBe

  • toBe(expected: Subject): void
  • Assert deep-equality between yielded subject and expected value

    example
    
      // 2 + 2 == 4
      cyr.expect(2+2).toBe(4)
    
      // {a: 1} == {a: 1}
      cyr.expect({a: 1}).toBe({a: 1})

    Parameters

    • expected: Subject

      value that should be deep-equal to actual value

    Returns void

toMatch

  • toMatch(expected: string): void

verify

  • verify(): Promise<void>

Static with

  • with<T>(e: T): Box<T>

Generated using TypeDoc