test.command.allowUnknownOption.js
This file
Path
test/test.command.allowUnknownOption.js
58 lines · 1.2 KiB · JavaScript
Last changed by
Merge pull request #417 from zhiyelee/zhiyelee/refactor_testZhiye Libefore adoption0238972
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859/** * Module dependencies. */var program = require('../') , sinon = require('sinon').sandbox.create() , should = require('should');
var stubError = sinon.stub(console, 'error');var stubExit = sinon.stub(process, 'exit');
program .version('0.0.1') .option('-p, --pepper', 'add pepper');program.parse('node test -m'.split(' '));
stubError.callCount.should.equal(3);
// test subcommandresetStubStatus();program .command('sub') .action(function () { });program.parse('node test sub -m'.split(' '));
stubError.callCount.should.equal(3);stubExit.calledOnce.should.be.true();
// command with `allowUnknownOption`resetStubStatus();program .version('0.0.1') .option('-p, --pepper', 'add pepper');program .allowUnknownOption() .parse('node test -m'.split(' '));
stubError.callCount.should.equal(0);stubExit.calledOnce.should.be.false();
// subcommand with `allowUnknownOption`resetStubStatus();program .command('sub2') .allowUnknownOption() .action(function () { });program.parse('node test sub2 -m'.split(' '));
stubError.callCount.should.equal(0);stubExit.calledOnce.should.be.false();
function resetStubStatus() { stubError.reset(); stubExit.reset();}