Skip to content

Commit

Permalink
feat(key): passed the current key to the objectWithKeys factory function
Browse files Browse the repository at this point in the history
closes #157
  • Loading branch information
travi committed Aug 12, 2017
1 parent 7946af1 commit 6318a79
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion any.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function objectWithKeys(keys, options = {}) {

keys.forEach(key => {
if (options.factory) {
object[key] = options.factory();
object[key] = options.factory(key);
} else {
object[key] = string();
}
Expand Down
4 changes: 3 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Produces a simple object with the keys defined from the provided list of keys
* `keys` (required): list of keys to be used for the produced object's keys
* `options`: object to provide configuration options
* `factory`: factory function to be used to create each of the values for the
produced object. defaults to [`string`](#string), if not provided
produced object
* receives the current key as `key`
* defaults to [`string`](#string), if not provided

### `objectWithKeys` examples

Expand Down
2 changes: 1 addition & 1 deletion test/unit/any-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ suite('random data generator', () => {

values[i] = value;

factory.onCall(i).returns(value);
factory.withArgs(keys[i]).returns(value);
}

const object = any.objectWithKeys(keys, {factory});
Expand Down

0 comments on commit 6318a79

Please sign in to comment.