diff --git a/packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts b/packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts index d311373d69f0..11228e4adca0 100644 --- a/packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts +++ b/packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts @@ -9,7 +9,7 @@ import { JsonObject, schema } from '@angular-devkit/core'; import yargs from 'yargs'; -import { addSchemaOptionsToCommand, parseJsonSchemaToOptions } from './json-schema'; +import { Option, addSchemaOptionsToCommand, parseJsonSchemaToOptions } from './json-schema'; describe('parseJsonSchemaToOptions', () => { describe('without required fields in schema', () => { @@ -21,10 +21,9 @@ describe('parseJsonSchemaToOptions', () => { }; let localYargs: yargs.Argv; - beforeEach(async () => { - // Create a fresh yargs for each call. The yargs object is stateful and - // calling .parse multiple times on the same instance isn't safe. - localYargs = yargs().exitProcess(false).strict().fail(false).wrap(1_000); + let options: Option[]; + + beforeAll(async () => { const jsonSchema = { 'type': 'object', 'properties': { @@ -118,12 +117,20 @@ describe('parseJsonSchemaToOptions', () => { }, }, }; + const registry = new schema.CoreSchemaRegistry(); - const options = await parseJsonSchemaToOptions( + options = await parseJsonSchemaToOptions( registry, jsonSchema as unknown as JsonObject, false, ); + }); + + beforeEach(async () => { + // Create a fresh yargs for each call. The yargs object is stateful and + // calling .parse multiple times on the same instance isn't safe. + localYargs = yargs().exitProcess(false).strict().fail(false).wrap(1_000); + addSchemaOptionsToCommand(localYargs, options, true); }); @@ -138,7 +145,15 @@ describe('parseJsonSchemaToOptions', () => { }); describe('type=array, enum', () => { - it('parses valid option value', async () => { + it('parses valid option value when specified once', async () => { + expect(await parse(['--arrayWithChoices', 'always', 'never'])).toEqual( + jasmine.objectContaining({ + 'arrayWithChoices': ['always', 'never'], + }), + ); + }); + + it('parses valid option value when specified multiple times', async () => { expect( await parse(['--arrayWithChoices', 'always', '--arrayWithChoices', 'never']), ).toEqual( @@ -160,7 +175,15 @@ describe('parseJsonSchemaToOptions', () => { }); describe('type=array, enum in oneOf', () => { - it('parses valid option value', async () => { + it('parses valid option value when specified once', async () => { + expect(await parse(['--arrayWithChoicesInOneOf', 'default', 'verbose'])).toEqual( + jasmine.objectContaining({ + 'arrayWithChoicesInOneOf': ['default', 'verbose'], + }), + ); + }); + + it('parses valid option value when specified multiple times', async () => { expect( await parse([ '--arrayWithChoicesInOneOf', @@ -183,7 +206,15 @@ describe('parseJsonSchemaToOptions', () => { }); describe('type=array, anyOf', () => { - it('parses valid option value', async () => { + it('parses valid option value when specified once', async () => { + expect(await parse(['--arrayWithComplexAnyOf', 'default', 'something-else'])).toEqual( + jasmine.objectContaining({ + 'arrayWithComplexAnyOf': ['default', 'something-else'], + }), + ); + }); + + it('parses valid option value when specified multiple times', async () => { expect( await parse([ '--arrayWithComplexAnyOf',