gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 23:14:29 24 4
gpt4 key购买 nike

有没有一种方法可以将自定义断言添加到传递给每个测试的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com