2011-12-16 3 views
4

각 테스트에 전달 된 NodeUnit test 객체에 사용자 정의 어설 션을 추가하는 방법이 있습니까?NodeUnit에 사용자 정의 어설 션을 추가하는 방법

내가 할 싶습니다 뭔가 같은 :

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
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(); 
    } 
}); 
관련 문제