Skip to content

Commit

Permalink
Merge pull request #248 from richardson-trevor/default-word
Browse files Browse the repository at this point in the history
fix(word): Fixed issue with passing length to `any.word`
  • Loading branch information
travi authored Aug 11, 2017
2 parents 494d22f + e96b53f commit 415cb6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion any.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ 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);
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);
Expand Down
8 changes: 8 additions & 0 deletions test/unit/any-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 415cb6f

Please sign in to comment.