How to add custom statements in Nodeunit

Is there a way to add custom statements to the NodeUnit test object that is passed to each test?

I would like to do something like:

 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
source share
1 answer
 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(); } }); 
+4
source

Source: https://habr.com/ru/post/1386692/


All Articles