4

有没有办法向传递给每个测试的 NodeUnittest对象添加自定义断言?

我想做类似的事情:

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();
}
4

1 回答 1

4
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();
    }
});
于 2012-01-17T22:29:09.690 回答