diff --git a/index.js b/index.js index 2e0867a..1bcd387 100644 --- a/index.js +++ b/index.js @@ -35,17 +35,15 @@ function getFakerSchema(schemaName) { * @param {{version?: string, count?: number}} [options] * @returns {Array>} */ -export function generate(schemaName, { count } = {}) { +export function generate(schemaName, { count = 0 } = {}) { isValidSchemaName(schemaName) const schema = getFakerSchema(schemaName) - const numberToGenerate = count || 1 - /** @type {Array>} */ const result = [] - for (let i = 0; i < numberToGenerate; i++) { + for (let i = 0; i < count; i++) { result.push( /** @type {Extract} */ ( JSONSchemaFaker.generate(schema) diff --git a/test/generate.test.js b/test/generate.test.js index 6954244..08bdb91 100644 --- a/test/generate.test.js +++ b/test/generate.test.js @@ -30,3 +30,11 @@ test('generates valid data', { concurrency: true }, async (t) => { } }) }) + +test('passing count=0 returns an empty array', () => { + const schemaNames = Object.keys(listSchemas()) + + for (const schemaName of schemaNames) { + assert.deepEqual(generate(schemaName, { count: 0 }), []) + } +})