Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send node command line arguments in jest test

Tags:

node.js

jestjs

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"]

like image 475
Pasupathi Rajamanickam Avatar asked Sep 19 '25 17:09

Pasupathi Rajamanickam


1 Answers

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.

like image 68
Daniele Scillia Avatar answered Sep 22 '25 09:09

Daniele Scillia