-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
I've encountered an odd behavior where subcommands in test env will re-use optional arguments from previous calls.
At the top level - you have a program and a subcommand with optional flags. Following calls behave oddly:
- Call
myapp subcommand --init
(correctly passesinit
as argument to handler) - Call
myapp subcommand --other 1234
(correctly passesother
as argument to handler, but also includesinit
from first call) - Call
myapp subscommand
(passes previous values forinit
andother
instead of empty args)
Is this behavior intended? If yes, how would one reset args between tests? The only way I've found so far was to monkey-patch subcommand _optionValues
which feels wrong 😅
I've created a small repro case in stackblitz: https://stackblitz.com/edit/node-nsyb1h?file=app.test.js
Calling npm test
executes it.
Uncommenting monkey-patching in the last test case makes it behave as expected (i.e. not pass any args when none given to parse
function).
Metadata
Metadata
Assignees
Labels
No labels