Skip to content

t.throws passes with false, undefined, and null #1676

Closed
@awmottaz

Description

@awmottaz

Description

t.throws() will pass if provided the arguments false, undefined and null. I would expect these tests to fail since, according to the docs:

error can be an error constructor, error message, regex matched against the error message, or validation function.

For my particular use case, I wanted to test that the error thrown was an instance of a custom error. However, the custom error was not implemented and so undefined was passed into t.throws(). The test still succeeded, which is not the desired behavior.

Test Source

The following tests will incorrectly pass

test('false', t => {
  t.throws(() => { throw new Error('foo') }, false)
})

test('undefined', t => {
  t.throws(() => { throw new Error('foo') }, undefined)
})

test('null', t => {
  t.throws(() => { throw new Error('foo') }, null)
})

Error Message & Stack Trace

▶ node_modules/.bin/ava -v

  ✔ false
  ✔ undefined
  ✔ null

  3 tests passed

Config

Using vanilla ava—no config

Command-Line Arguments

ava -v

Environment

▶ node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"
Node.js v8.9.4
linux 4.13.0-32-generic

▶ node_modules/.bin/ava --version
0.25.0

▶ npm --version
5.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcurrent functionality does not work as desiredscope:assertions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions