Pasupathi Rajamanickam
Pasupathi Rajamanickam

Reputation: 2052

How to send node command line arguments in jest test

I have a utility.js which uses program arguments through process.argv.

When I run jest -t 'utility-spec' --arg1 value1 --arg2 value2 it's throwing exception. Failed to run the test.

(node:8956) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ● Unrecognized CLI Parameters:

Following options were not recognized: ["arg1", "arg2"]

Upvotes: 4

Views: 6619

Answers (1)

Daniele Scillia
Daniele Scillia

Reputation: 129

Just ran into the same question and found this answer:

Jest doesn't accept node arguments unfortunately. I recommend testing your utility by making a programmatic interface. You can also overwrite process.argv in your test before requiring your module.

Issue 5089

Seems like it's not possible.

Upvotes: 2

Related Questions