-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Add array.exactShape
predicate
#187
Conversation
source/predicates/array.ts
Outdated
/** | ||
Test an array to match the `predicates` exactly. | ||
|
||
The predicates is an array which describes how the tested array should look like. Each predicate is the same as the source array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the docs here could be written clearer.
hi @sindresorhus, i have updated the doc, thanks. |
test/array.ts
Outdated
|
||
t.throws(() => { | ||
ow(['🦄', {isFirstCommit: true}, 'nope', 5, {accepted: false}], ow.array.exactShape([ow.string, ow.object.exactShape({isFirstCommit: ow.boolean}), ow.string])); | ||
}, 'Did not expect property `3` to exist, got `5` in array'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is sub-optimal. It should talk about array elements, not properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added isArray as an option in exact method declaration to be able to change error message
source/predicates/array.ts
Outdated
/** | ||
Test all elements in the array to match the exact shape of the provided predicate. | ||
|
||
The predicates is an array which describes how the tested array should look like. Each predicate placed at the nth index should be applied to the item at the same index. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could still be written more succinctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sindresorhus what about this?
/**
Test if the nth element in the array exactly matches with the element placed at the same index in the predictions.
The predicates is an array which describes how the tested array should look like.
@param predicates - Predicates to test the array against.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sounds better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have updated the docs, and synced with repo.
source/predicates/array.ts
Outdated
|
||
The predicates is an array which describes how the tested array should look like. Each predicate placed at the nth index should be applied to the item at the same index. | ||
|
||
@param predicates - The predicate placed at the nth index should be applied also to the item at the same index. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just repeating the above. It should actually describe what predicates
is.
exactShape implementation for array.
Fixes #179