Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(word): Fixed issue with passing length to any.word #248

Merged
merged 1 commit into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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