Skip to content

Commit

Permalink
mock process.argv in test
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Jul 14, 2023
1 parent 7ec911f commit 051dea3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/util/getCliOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { getCliOptions } from './getCliOptions';
import * as cliHelper from './getParsedCliOptions';

describe('getCliOptions', () => {
let originalArgv: string[] = process.argv;

afterEach(() => {
process.argv = originalArgv;
});

it('returns custom options if passed', () => {
const customConfig = { configDir: 'custom', indexJson: true };
jest
Expand All @@ -13,6 +19,9 @@ describe('getCliOptions', () => {

it('returns extra args if passed', () => {
const extraArgs = ['TestName', 'AnotherTestName'];
// mock argv to avoid side effect from running tests e.g. jest --coverage,
// which would end up caught by getCliOptions
process.argv = [];
jest.spyOn(cliHelper, 'getParsedCliOptions').mockReturnValueOnce({ options: {}, extraArgs });
const opts = getCliOptions();
expect(opts.jestOptions).toEqual(extraArgs);
Expand Down

0 comments on commit 051dea3

Please sign in to comment.