Skip to content

Commit

Permalink
Add test for interaction of opts.strict and opts.unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Jun 24, 2023
1 parent 8621db5 commit 10508f8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/strict.js
Expand Up @@ -130,3 +130,25 @@ test('strict unknown option: opt.alias is known', function (t) {
});
t.end();
});

test('strict unknown option: opts.unknown returns false', function (t) {
// Mirror non-strict and skip argument processing if opts.unknown returns false.
// Otherwise, throw for unknown option as usual.

function unknownFn() {
}
function unknownFnTrue() {
return true;
}
function unknownFnFalse() {
return false;
}

throwsWhenStrict(['--x=y'], { unknown: unknownFn }, { t: t, expected: kUnknownOption });
throwsWhenStrict(['--x=y'], { unknown: unknownFnTrue }, { t: t, expected: kUnknownOption });
t.doesNotThrow(function () {
parse(['--x=y'], { strict: true, unknown: unknownFnFalse });
});

t.end();
});

0 comments on commit 10508f8

Please sign in to comment.