unit testing - How do I test that a specific exception is thrown in node.js and tap -
i use assert(...)
on methods 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 using tap , write test validate assert exception thrown. cannot test error thrown, because assert early-guard. bad input throw error.
you compare against assert.assertionerror
in t.throws()
e.g.
var test = require('tap').test test('calling somefunction without arguments', function(t){ t.throws(function(){ somefunction() }, new assert.assertionerror({ message: 'a required' }), 'throws assert error') t.end() })
the assertionerror
takes object in it's constructor .message
property compared against thrown exception.
Comments
Post a Comment