Skip to content

Commit

Permalink
test(): add test for "strict" flag
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Sep 28, 2021
1 parent aec631f commit de611bc
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions test/lib/schematics/schematic.option.spec.ts
@@ -1,7 +1,25 @@
import { SchematicOption } from '../../../lib/schematics';

interface TestOption {
input: string;
expected: string;
}

interface TestFlag {
input: boolean;
}

type TestSuite = {
description: string;
option: string;
} & (TestOption | TestFlag);

function isFlagTest(test: any): test is TestFlag {
return typeof test.expected === 'undefined';
}

describe('Schematic Option', () => {
[
const tests: TestSuite[] = [
{
description: 'should manage string option name',
option: 'name',
Expand Down Expand Up @@ -50,6 +68,16 @@ describe('Schematic Option', () => {
input: 'name <name@example.com>',
expected: '"name <name@example.com>"',
},
{
description: 'should use "strict" mode',
option: 'strict',
input: true,
},
{
description: 'should not use "strict" mode',
option: 'strict',
input: false,
},
{
description: 'should manage version',
option: 'version',
Expand All @@ -62,12 +90,23 @@ describe('Schematic Option', () => {
input: 'path/to/generate',
expected: 'path/to/generate',
},
].forEach((test) => {
];

tests.forEach((test) => {
it(test.description, () => {
const option = new SchematicOption(test.option, test.input);
expect(option.toCommandString()).toEqual(
`--${test.option}=${test.expected}`,
);

if (isFlagTest(test)) {
if (test.input) {
expect(option.toCommandString()).toEqual(`--${test.option}`);
} else {
expect(option.toCommandString()).toEqual(`--no-${test.option}`);
}
} else {
expect(option.toCommandString()).toEqual(
`--${test.option}=${test.expected}`,
);
}
});
});

Expand Down

0 comments on commit de611bc

Please sign in to comment.