0

我正在为 Grunt 编写一个插件,我想在插件的单元测试中添加一个自定义断言。

我找到了这个关于向 NodeUnit 添加自定义断言的答案。所以我编辑了 Grunt 生成的测试用例模板,我写了如下内容:

'use strict';

var grunt = require('grunt');
var assert = require('nodeunit').assert;

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.my_plugin = {
  setUp: function(done, test) {
    done();
  },
  first_test_case: function(test) {
    test.isVowel("e", 'It should be a vowel.');
    test.done();
  }
};

但是,这是行不通的。测试用例以TypeError: Object #<Object> has no method 'isVowel'.

我也尝试assert.isVowelsetUp函数中声明,结果相同。任何想法?

4

0 回答 0