Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gruntjs 如何为Grunt插件项目在Nodeunit中添加自定义断言_Gruntjs_Nodeunit_Grunt Plugins - Fatal编程技术网

Gruntjs 如何为Grunt插件项目在Nodeunit中添加自定义断言

Gruntjs 如何为Grunt插件项目在Nodeunit中添加自定义断言,gruntjs,nodeunit,grunt-plugins,Gruntjs,Nodeunit,Grunt Plugins,我正在为Grunt编写一个插件,我想在插件的单元测试中添加一个自定义断言 我发现这个答案很简单。因此,我编辑了Grunt生成的测试用例模板,并编写了如下内容: 'use strict'; var grunt = require('grunt'); var assert = require('nodeunit').assert; assert.isVowel = function(letter, message) { var vowels = [ 'a', 'e', 'i', 'o',

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

我发现这个答案很简单。因此,我编辑了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#没有方法“isVowel”


我还尝试在
setUp
函数中声明
assert.is元音
,结果相同。有什么想法吗?

我不这么认为。如果是,还需要有人向我解释如何使用该解决方案:)