Files
freeCodeCamp/tools/challenge-helper-scripts/helpers/get-arg-values.test.ts
Oliver Eyton-Williams 7216ca55cc refactor: organise TypeScript config and migrate helpers (#44747)
* feat: allow more 1000 steps to be created at once

* refactor: start migrating to typescript

* refactor: delete-step to ts

* refactor: migrated some helpers

* refactor: migrate create-empty-steps

* refactor: migrate create-step-between

* refactor: finish migrating to TS

* refactor: migrate tests

* fix: ensure mock.restore is done after each test

* fix: prevent double-tscing

* fix: repair the tests

* chore: use ts-node for scripts

We don't need the performance boost of incremental compilation and
ts-node is easier to work with

* refactor: consolidate tsconfigs

* refactor: replace gulp

* fix: use ts-node for build-curriculum

* fix: allow ts compilation of config

* feat: create and use create:config script

* fix: add /config to eslint projects

* fix: remove gulp script
2022-01-25 11:34:16 +01:00

35 lines
1.2 KiB
TypeScript

import { getArgValues } from './get-arg-values';
describe('getArgValues helper', () => {
it('should be able to run if there are no values to process', () => {
const args = ['/Path/to/node', '/Path/to/script'];
expect(getArgValues(args)).toEqual({});
expect(getArgValues()).toEqual({});
});
it('should parse the third element (key/value) if provided', () => {
const args = ['/Path/to/node', '/Path/to/script', 'num=4'];
expect(getArgValues(args)).toEqual({ num: '4' });
});
it('should parse multiple arguments (key/value) if provided', () => {
const args = ['/Path/to/node', '/Path/to/script', 'num=4', 'another=5'];
expect(getArgValues(args)).toEqual({ another: '5', num: '4' });
});
it('should parse the arguments with spaces (key/value) if provided', () => {
const args = ['/Path/to/node', '/Path/to/script', 'num = 3'];
expect(getArgValues(args)).toEqual({ num: '3' });
});
it('should throw error on invalid key/value arguments', () => {
const items = [
['/Path/to/node', '/Path/to/script', 'num='],
['/Path/to/node', '/Path/to/script', '='],
['/Path/to/node', '/Path/to/script', 'num=2', '= 3']
];
items.forEach(item => expect(() => getArgValues(item)).toThrow());
});
});