[英]How to write unit tests for a grunt plugin that doesn't write files?
我正在創建一個grunt插件,該插件負責在文件中查找URL並使用以下命令將這些URL添加到grunt文件中的變量中
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-plugins的Yo生成器(*)基本上是在設置如下測試:
Gruntconfig.js
以使用特定的testconfig運行您的插件 grunt.registerTask('test', ['myPlugin', 'nodeunit']);
。 這意味着您的插件應已設置要測試的配置值。 test.equal(grunt.config.get('urls'), 'http://foo.example.com', 'Should ...');
Yo生成器由Addy Osmani和Stephen Sawchuck維護,它們可能被認為是可靠的來源;-)
(*) npm install -g generator-gruntplugin
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.