Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/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
Javascript 如何为没有';你不写文件吗?_Javascript_Unit Testing_Plugins_Gruntjs_Grunt Plugins - Fatal编程技术网

Javascript 如何为没有';你不写文件吗?

Javascript 如何为没有';你不写文件吗?,javascript,unit-testing,plugins,gruntjs,grunt-plugins,Javascript,Unit Testing,Plugins,Gruntjs,Grunt Plugins,我正在创建一个grunt插件,它负责查找文件中的URL,并使用 grunt.config.set('urls', urls); Grunt插件的所有单元测试示例都假定插件将编写一个文件,然后将该输出与测试文件进行比较,并将结果与“预期”结果进行比较 有没有办法测试我的Grunt插件是否设置了配置变量?类似的东西 urlConfigTest: function(test) { test.expect(1); grunt.config.set('urls','http://foo.

我正在创建一个grunt插件,它负责查找文件中的URL,并使用

grunt.config.set('urls', urls);
Grunt插件的所有单元测试示例都假定插件将编写一个文件,然后将该输出与测试文件进行比较,并将结果与“预期”结果进行比较

有没有办法测试我的Grunt插件是否设置了配置变量?

类似的东西

urlConfigTest: function(test) {
    test.expect(1);
    grunt.config.set('urls','http://foo.example.com');
    test.equal(grunt.config.get('urls'), 'http://foo.example.com', 'Should set foo to the grunt configuration.');
    test.done();
}
grunt插件的Yo生成器(*)基本上是这样设置测试的:

  • 设置
    Gruntconfig.js
    以使用特定的testconfig运行插件
  • 然后通过创建测试任务来配置测试运行:
    grunt.registerTask('test',['myPlugin','nodeunit'])。这意味着您的插件应该已经设置了您想要测试的配置值
  • 运行测试,如
    test.equal(grunt.config.get('url'),'http://foo.example.com","应该",
  • Yo发电机由Addy Osmani和Stephen Sawcuck维护,这可能被视为可靠来源;-)


    (*)
    npm安装-g generator gruntplugin

    工作正常。我没有意识到脚手架测试文件中对grunt的引用实际上保持了当前状态。