有没有一种方法可以向传递给每个测试的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();
}发布于 2012-01-18 06:29:10
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();
}
});https://stackoverflow.com/questions/8533757
复制相似问题