Skip to content

Commit

Permalink
feat(word): Word generation now defaults to 3 syllables
Browse files Browse the repository at this point in the history
Previously issues were being caused by times when keys were being generated as `id` for example.
This caused issues when wanting to do things like `{[any.word()]: any.string(), id:
any.simpleObject()}` as the desired 'id' key would get stomped.
  • Loading branch information
Trevor Richardson committed Jul 27, 2017
1 parent ea8bc92 commit d3d4819
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions any.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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(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);
Expand All @@ -29,7 +29,7 @@ function simpleObject() {
const size = integer(DEFAULT_SIZE_RANGE);

for (let i = 0; i < size; i += 1) {
object[word({syllables: 3})] = string();
object[word()] = string();
}

return object;
Expand Down
10 changes: 9 additions & 1 deletion test/unit/any-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ suite('random data generator', () => {

test('that a word is generated', () => {
const word = chance.word();
chanceStub.word.withArgs(options).returns(word);
chanceStub.word.withArgs({syllables: 3, ...options}).returns(word);

assert.equal(any.word(options), word);
});

test('that syllables can be overridden', () => {
const word = chance.word();
const expectedSyllables = any.integer();
chanceStub.word.withArgs({syllables: expectedSyllables, ...options}).returns(word);

assert.equal(any.word({syllables: expectedSyllables, ...options}), word);
});

test('that a sentence is generated', () => {
const sentence = chance.sentence();
chanceStub.sentence.withArgs(options).returns(sentence);
Expand Down

0 comments on commit d3d4819

Please sign in to comment.