Skip to content

Commit 9f8dfb4

Browse files
committed
test: add test cases for parsing array options specified multiple times
Add some more tests for arrays. (cherry picked from commit 0a61f20)
1 parent a2e9e07 commit 9f8dfb4

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,24 @@ describe('parseJsonSchemaToOptions', () => {
145145
});
146146

147147
describe('type=array, enum', () => {
148-
it('parses valid option value', async () => {
148+
it('parses valid option value when specified once', async () => {
149149
expect(await parse(['--arrayWithChoices', 'always', 'never'])).toEqual(
150150
jasmine.objectContaining({
151151
'arrayWithChoices': ['always', 'never'],
152152
}),
153153
);
154154
});
155155

156+
it('parses valid option value when specified multiple times', async () => {
157+
expect(
158+
await parse(['--arrayWithChoices', 'always', '--arrayWithChoices', 'never']),
159+
).toEqual(
160+
jasmine.objectContaining({
161+
'arrayWithChoices': ['always', 'never'],
162+
}),
163+
);
164+
});
165+
156166
it('rejects non-enum values', async () => {
157167
await expectAsync(parse(['--arrayWithChoices', 'yes'])).toBeRejectedWithError(
158168
/Argument: array-with-choices, Given: "yes", Choices:/,
@@ -165,14 +175,29 @@ describe('parseJsonSchemaToOptions', () => {
165175
});
166176

167177
describe('type=array, enum in oneOf', () => {
168-
it('parses valid option value', async () => {
178+
it('parses valid option value when specified once', async () => {
169179
expect(await parse(['--arrayWithChoicesInOneOf', 'default', 'verbose'])).toEqual(
170180
jasmine.objectContaining({
171181
'arrayWithChoicesInOneOf': ['default', 'verbose'],
172182
}),
173183
);
174184
});
175185

186+
it('parses valid option value when specified multiple times', async () => {
187+
expect(
188+
await parse([
189+
'--arrayWithChoicesInOneOf',
190+
'default',
191+
'--arrayWithChoicesInOneOf',
192+
'verbose',
193+
]),
194+
).toEqual(
195+
jasmine.objectContaining({
196+
'arrayWithChoicesInOneOf': ['default', 'verbose'],
197+
}),
198+
);
199+
});
200+
176201
it('rejects non-enum values', async () => {
177202
await expectAsync(parse(['--arrayWithChoicesInOneOf', 'yes'])).toBeRejectedWithError(
178203
/Argument: array-with-choices-in-one-of, Given: "yes", Choices:/,
@@ -181,13 +206,28 @@ describe('parseJsonSchemaToOptions', () => {
181206
});
182207

183208
describe('type=array, anyOf', () => {
184-
it('parses valid option value', async () => {
209+
it('parses valid option value when specified once', async () => {
185210
expect(await parse(['--arrayWithComplexAnyOf', 'default', 'something-else'])).toEqual(
186211
jasmine.objectContaining({
187212
'arrayWithComplexAnyOf': ['default', 'something-else'],
188213
}),
189214
);
190215
});
216+
217+
it('parses valid option value when specified multiple times', async () => {
218+
expect(
219+
await parse([
220+
'--arrayWithComplexAnyOf',
221+
'default',
222+
'--arrayWithComplexAnyOf',
223+
'something-else',
224+
]),
225+
).toEqual(
226+
jasmine.objectContaining({
227+
'arrayWithComplexAnyOf': ['default', 'something-else'],
228+
}),
229+
);
230+
});
191231
});
192232

193233
describe('type=string, enum', () => {

0 commit comments

Comments
 (0)