deprecated.test.js
This file
Path
tests/deprecated.test.js
31 lines · 1.3 KiB · JavaScript
Last changed by
Merge remote-tracking branch 'origin/develop' into release/10.xJohn Geebefore adoptione0f6173
History of this fileTake it
1234567891011121314151617181920212223242526272829303132const commander = require('../');
// Test for backwards compatible behaviour of deprecated features that don't fit in elsewhere.// We keep deprecated features working (when not too difficult) to avoid breaking existing code// and reduce barriers to updating to latest version of Commander.
describe('option with regular expression instead of custom processing function', () => { test('when option not given then value is default', () => { const program = new commander.Command(); program .option('--cheese <type>', 'cheese type', /mild|tasty/, 'mild'); program.parse([], { from: 'user' }); expect(program.opts().cheese).toEqual('mild'); });
test('when argument matches regexp then value is as specified', () => { const program = new commander.Command(); program .option('--cheese <type>', 'cheese type', /mild|tasty/, 'mild'); program.parse(['--cheese', 'tasty'], { from: 'user' }); expect(program.opts().cheese).toEqual('tasty'); });
test('when argument does not match regexp then value is default', () => { const program = new commander.Command(); program .option('--cheese <type>', 'cheese type', /mild|tasty/, 'mild'); program.parse(['--cheese', 'other'], { from: 'user' }); expect(program.opts().cheese).toEqual('mild'); });});