diff --git a/src/validate.js b/src/validate.js index 7e86cee..5eb7309 100644 --- a/src/validate.js +++ b/src/validate.js @@ -24,7 +24,7 @@ function validate(schema, options, configuration = {}) { let errors = []; if (Array.isArray(options)) { - errors = options.map((nestedOptions) => + errors = Array.from(options).map((nestedOptions) => validateObject(schema, nestedOptions) ); diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index 3ebc2d9..424352d 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -639,6 +639,12 @@ exports[`Validation should fail validation for formatMinimum 1`] = ` - configuration.formatMinimumKeyword should be >= \\"2016-02-06\\"." `; +exports[`Validation should fail validation for holey array 1`] = ` +"Invalid configuration object. Object has been initialised using a configuration object that does not match the API schema. + - configuration[1] should be an object: + object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions?, minLengthOne?, minLengthTwo?, integerType?, nullType?, allOfRef?, customObject?, objectType?, anyOfKeyword?, nestedArrayWithoutItems?, nestedObjectWithoutItems?, arrayType?, arrayType2?, multipleTypes?, zeroMaxItems?, multipleContains?, multipleContains2?, exclusiveMinimumKeyword?, exclusiveMaximumKeyword?, uniqueItemsKeyword?, minPropertiesKeyword?, maxPropertiesKeyword?, requiredKeyword?, requiredKeywordWithAdditionalProperties?, enumKeyword?, formatMinimumKeyword?, formatMaximumKeyword?, formatExclusiveMinimumKeyword?, formatExclusiveMaximumKeyword?, formatMinMaxExclusiveMinKeyword?, formatMinMaxExclusiveMaxKeyword?, minItemsKeyword?, maxItemsKeyword?, itemsKeyword?, itemsKeyword2?, additionalItemsKeyword?, additionalItemsKeyword2?, additionalItemsKeyword3?, additionalItemsKeyword4?, propertiesKeyword?, patternPropertiesKeyword?, patternPropertiesKeyword2?, arrayWithOnlyNumber?, onlyRequired?, dependenciesKeyword?, dependenciesKeyword2?, patternRequiredKeyword?, patternRequiredKeyword2?, onlyProperties?, onlyProperties2?, onlyItems?, onlyItems2?, onlyAdditionalItems?, booleanType?, additionalPropertiesKeyword?, additionalPropertiesKeyword2?, propertyNamesKeyword?, constKeyword?, constKeyword2?, ifThenElseKeyword?, ifThenElseKeyword2?, stringKeyword?, arrayKeyword?, arrayKeyword2?, arrayKeyword3?, arrayKeyword4?, arrayKeyword5?, arrayKeyword6?, arrayKeyword7?, arrayKeyword8?, arrayKeyword9?, arrayKeyword10?, arrayKeyword11?, arrayKeyword12?, arrayKeyword13?, arrayKeyword14?, arrayKeyword15?, arrayKeyword16?, arrayKeyword17?, arrayKeyword18?, arrayKeyword19?, recursion?, extending?, longString?, integerWithMinimum?, integerWithExclusiveMinimum?, integerWithExclusiveMaximum?, numberWithMinimum?, multipleOfProp?, stringWithMinAndMaxLength?, strictFormat?, strictFormat2?, uniqueItemsProp?, numberAndDescription?, oneOfnumberAndDescriptionAndArray?, maxPropertiesAndMinProperties?, objectTest?, objectTest2?, objectTest3?, objectTest4?, objectTest5?, objectTest6?, objectTest7?, objectTest8?, objectTest9?, stringWithEmptyPattern?, likeArray?, arrayWithEmptyItemsAndEmptyAdditionalItemsAndEmptyContains?, numberWithoutType?, numberWithoutType2?, stringWithoutType?, arrayWithoutType?, additionalItemsFalse?, requiredWithoutType?, dependenciesWithoutType?, propertyNamesWithoutType?, patternRequiredWithoutType?, additionalPropertiesWithoutType?, maxPropertiesWithoutType?, justAnObject?, arrayWithAbsolutePath?, allOfKeyword?, enumWithDescription?, constWithDescription?, itemsTrue?, emptyConst?, oneConst?, constWithEmptyString?, refAndAnyOf?, additionalPropertiesInsideOneOf?, additionalPropertiesInsideOneOf2?, singleContainsItems?, objectWithPropertyDependency?, objectWithPropertyDependency2?, objectWithPropertyDependency3?, objectWithPropertyDependency4?, oneOfWithIf?, constWithArrayNotation?, constWithObjectNotation?, additionalItemsWithoutType?, additionalItemsWithoutType2?, additionalItemsWithoutType3?, containsAndAdditionalItems?, containsInsideItem?, emptyObject?, nonEmptyObject?, nonEmptyObject2? }" +`; + exports[`Validation should fail validation for if/then/else #2 1`] = ` "Invalid configuration object. Object has been initialised using a configuration object that does not match the API schema. - configuration.ifThenElseKeyword should match \\"then\\" schema: diff --git a/test/index.test.js b/test/index.test.js index 34c7640..5813d48 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -2165,4 +2165,19 @@ describe('Validation', () => { }, (msg) => expect(msg).toMatchSnapshot() ); + + createFailedTestCase( + 'holey array', + // eslint-disable-next-line no-sparse-arrays + [ + { + mode: 'production', + }, + , + { + mode: 'development', + }, + ], + (msg) => expect(msg).toMatchSnapshot() + ); });