如何在Nodeunit中添加自定义断言

有没有办法将自定义断言添加到传递给每个testing的NodeUnit test对象?

我想要做一些事情:

 var Test = require('nodeunit').Test; Test.prototype.customAssertion = function(obj) { test.same(obj.foo, 'bar'); test.same(obj.bar, 'baz'); } exports.test = function(test) { test.customAssertion(obj); test.done(); } 

       

网上收集的解决方案 "如何在Nodeunit中添加自定义断言"

 var assert = require('nodeunit').assert; var testCase = require('nodeunit').testCase; assert.isVowel = function(letter, message) { var vowels = [ 'a', 'e', 'i', 'o', 'u' ]; if (vowels.indexOf(letter) == -1) { assert.fail(letter, vowels.toString(), message, 'is not in'); } }; exports["Vowel"] = testCase({ "e should be a vowel": function(test) { test.isVowel("e", 'It should be a vowel.'); test.done(); } });