Options
All
  • Public
  • Public/Protected
  • All
Menu
file

Reason

author

Cuttle Cong

date

2018/4/11

description

Hierarchy

Index

Constructors

constructor

  • new Reason(expect?: any, actual?: any): Reason

Properties

Optional actual

actual: any

Optional expect

expect: any

msg

msg: string | null | Function = null

prefix

prefix: string = ""

suffix

suffix: string = ""

Methods

clone

hasMessage

  • hasMessage(): boolean

message

  • message(msg?: null | string | Function): Reason
  • set message

    be('2').message('error').toUnlawfulString(2) === 'error'
    be('2').message('error').message().toUnlawfulString(2) === "expected: '2', actual: 2."
    

    Nested case

    const r = equal({
      a: 2,
      b: {
        c: '2',
        d: be('d').message('errr')
      },
      // placeholder: `:expected:` `:actual:`
      c: be('xxxx').message(':expected: :actual: error .c')
    }).message('error equal')
    
    expect(r.toUnlawfulString({ a: 2, x: '22', b: { c: '2', d: 'd' } })).toBe(
      'error equal'
    )
    expect(r.toUnlawfulString({ a: 2, c: 'xxxx', b: { c: '2', d: 'd' } })).toBe(
      ''
    )
    expect(r.toUnlawfulString({ a: 2, c: 'xxxw', b: { c: '2', d: 'd' } })).toBe(
      "c: '2' 'xxxw' error .c"
    )
    expect(
      r.toUnlawfulString({ a: 2, c: 'xxxx', b: { c: '2', d: 'dd' } })
    ).toBe("b['d']: errr")
    

    Parameters

    • Default value msg: null | string | Function = null

    Returns Reason

setPrefix

  • setPrefix(prefix: string): this

setSuffix

  • setSuffix(suffix: string): this

toActualString

  • toActualString(): any

toExpectedString

  • toExpectedString(): any

Protected toHumanMessage

  • toHumanMessage(): string

toString

  • toString(): string

Generated using TypeDoc