-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to send node command line arguments in jest test #5089
Comments
Jest doesn't accept node arguments unfortunately. I recommend testing your utility by making a programmatic interface. You can also overwrite |
@cpojer Can you please show us a sample how to do that? |
@rambabusaravanan
|
This should not be blocking at all... My Jenkins jobs crash because of that errors, with proxy configuration... |
For convenience, and in case Repl.it disappears in the future, here is the code that @SimenB linked to in their comment: test.jsprocess.argv = ['node', 'jest', '--arg1', '1', '--arg2', 'hello']
const argv = require('./argv');
test('argv', () => {
expect(argv).toEqual(['--arg1', '1', '--arg2', 'hello']);
}); argv.jsmodule.exports = process.argv.slice(2); |
It's worth noting that this also works if you put it in a jest setup file Jest configuration - jest.config.js module.exports = {
setupFiles: ['./setup'],
}; Setup File - setup.js process.argv = ['node', 'jest', 'arg1', 'arg2']; |
|
This information might be useful to someone: I have an There is a single test file: test('database', () => {
return new Promise(function(resolve, reject) {
dbConnect(function(err, db) {
if (err) return reject(err);
resolve(db);
});
});
});
A very bad workaround is running with I was surprised when my tests broke after "not changing anything", not realizing what I did was adding a second test file, which then broke everything. But I didn't see it mentioned anywhere that I've tried other methods of injecting my custom
Setup file: require('babel-plugin-require-context-hook/register')();
require('regenerator-runtime/runtime'); |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
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"]
How to pass my program argument.?
The text was updated successfully, but these errors were encountered: