From e96b53f27cfe32c8bf4ac2db60d85065806f84cd Mon Sep 17 00:00:00 2001 From: Trevor Richardson Date: Fri, 11 Aug 2017 10:09:03 -0500 Subject: [PATCH] fix(word): Fixed issue with passing length to `any.word` Since we started defaulting to passing syllables we broke the ability to pass `length` as `chance.word` does not allow passing both length & syllables. - closes travi/any#246 --- any.js | 5 ++++- test/unit/any-test.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/any.js b/any.js index f0d619db..8de55b3d 100644 --- a/any.js +++ b/any.js @@ -16,7 +16,6 @@ const DEFAULT_SIZE_RANGE = {max: 20, min: 1}; const integer = options => chance.natural(options); const float = options => chance.floating(options); const string = options => chance.string(options); -const word = options => chance.word({syllables: 3, ...options}); const sentence = options => chance.sentence(options); const paragraph = options => chance.paragraph(options); const url = options => chance.url(options); @@ -24,6 +23,10 @@ const boolean = options => chance.bool(options); const email = options => chance.email(options); const date = () => chance.date({string: true}); +function word(options = {}) { + return options.length ? chance.word(options) : chance.word({syllables: 3, ...options}); +} + function simpleObject() { const object = {}; const size = integer(DEFAULT_SIZE_RANGE); diff --git a/test/unit/any-test.js b/test/unit/any-test.js index 596ee135..f13e23f6 100644 --- a/test/unit/any-test.js +++ b/test/unit/any-test.js @@ -61,6 +61,14 @@ suite('random data generator', () => { assert.equal(any.word({syllables: expectedSyllables, ...options}), word); }); + test('that length can be used', () => { + const word = chance.word(); + const length = chance.integer(); + chanceStub.word.withArgs({length, ...options}).returns(word); + + assert.equal(any.word({length, ...options}), word); + }); + test('that a sentence is generated', () => { const sentence = chance.sentence(); chanceStub.sentence.withArgs(options).returns(sentence);