Function notThrows

  • check if function throws an error

    Parameters

    • callback: ThrowsCallback
    • Optionalmessage: string

    Returns void

    throws(() => { throw new Error('foo'); });
    
    throws(() => { throw new TypeError('foo'); }, TypeError);
    
  • check if function throws an error matching the constructor

    Parameters

    • callback: ThrowsCallback
    • expectedError: Constructor<any>
    • Optionalmessage: string

    Returns void

    throws(() => { throw new TypeError('foo'); }, TypeError);
    
  • check if function throws an error matching the regex

    Parameters

    • callback: ThrowsCallback
    • expectedError: RegExp
    • Optionalmessage: string

    Returns void

    throws(() => { throw new Error('foo'); });
    
    throws(() => { throw new TypeError('foo'); }, /foo/);
    
  • check if function throws an error matching the predicate function

    Parameters

    • callback: ThrowsCallback
    • expectedError: ErrorPredicate
    • Optionalmessage: string

    Returns void

    throws(() => { throw new TypeError('foo'); }, (error) => error.message === 'foo');