samedi 25 avril 2015

How do I test that a specific exception is thrown in node.js and tap

I use assert(...) on methods to validate arguments, e.g.

var assert = require('assert')

function someFunction(a, b, c) {
  assert(a, 'a required')
  assert(b, 'b required')
  assert(c, 'c required')
}

I am using tap and would like to write a test to validate that an assert exception was thrown. I cannot just test that another error is thrown, because the assert is essentially an early-guard. The bad input will eventually throw an error.

Aucun commentaire:

Enregistrer un commentaire