作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
有没有一种方法可以将自定义断言添加到传递给每个测试的 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();
}
最佳答案
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();
}
});
关于testing - 如何在 Nodeunit 中添加自定义断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8533757/
我是一名优秀的程序员,十分优秀!