avajs/ava

No stack trace for exceptions in throws/notThrows #1372

CherryDT posted onGitHub

Description

When a test fails due to a t.notThrows throwing or a t.throws throwing the wrong type of exception, there is no stack trace in the output, only the toString representation of the error. This makes it hard to debug such issues.

Test Source

const test = require('ava')

function throwError () {
    throw new Error('uh-oh')
}

test('it shows no useful stack trace for t.notThrows encountering an exception', t => {
    t.notThrows(() => throwError())
})

test('it shows no useful stack trace for t.throws encountering unexpected exception types', t => {
    t.throws(() => throwError(), TypeError)
})

test('it does show useful stack trace for other exceptions', t => {
    throwError()
})

Output:

david@CHE-X1:~/z/Temp $ ava test.spec.js

  3 failed

  it shows no useful stack trace for t.notThrows encountering an exception
  /mnt/c/Users/david/Temp/test.spec.js:8

   7: test('it shows no useful stack trace for t.notThrows encountering an exception', t => {
   8:   t.notThrows(() => throwError())
   9: })

  Threw:

    [Error: uh-oh]




  it shows no useful stack trace for t.throws encountering unexpected exception types
  /mnt/c/Users/david/Temp/test.spec.js:12

   11: test('it shows no useful stack trace for t.throws encountering unexpected exception types', t => {
   12:   t.throws(() => throwError(), TypeError)
   13: })

  Threw unexpected exception:

    [Error: uh-oh]




  it does show useful stack trace for other exceptions
  /mnt/c/Users/david/Temp/test.spec.js:4

   3: function throwError () {
   4:   throw new Error('uh-oh')
   5: }

  Error thrown in test

  Error:

    [Error: uh-oh]

  throwError (test.spec.js:4:8)
  Test.t [as fn] (test.spec.js:16:2)

As shown here, only the last case prints a stack trace. I would like to see a similar output for the other two cases.

Environment

david@CHE-X1:~/z/Temp $ node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"
Node.js v7.6.0
linux 4.4.0-43-Microsoft
david@CHE-X1:~/z/Temp $ ava --version
0.19.1
david@CHE-X1:~/z/Temp $ npm --version
4.1.2

Fund this Issue

$80.00
Rewarded

Rewarded pull request

Recent activities

dflupu was rewarded by sindresorhus for avajs/ava# 1372
almost 6 years ago
dflupu submitted an output to  avajs/ ava# 1372
almost 6 years ago