process
是nodejs应用程序中的全局变量,因此您应该能够在测试中设置所需的参数。你可以重置
process.argv
使用
afterEach
钩子。
var assert = require('assert');
describe('Wenn calling index.js', function() {
describe('with arguments arg1 arg2', function() {
afterEach(function(){
process.argv = process.argv.slice(0,2);
});
it('should should fail because of "missing argument outFile"', function() {
process.argv[3] = "param templateName";
require("path/to/index.js");
});
});
});