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 assertion message for .all
and .any
#132
Fix assertion message for .all
and .any
#132
Conversation
source/index.ts
Outdated
@@ -388,9 +388,11 @@ is.any = (predicate: Predicate | Predicate[], ...values: unknown[]): boolean => | |||
|
|||
is.all = (predicate: Predicate, ...values: unknown[]): boolean => predicateOnArray(Array.prototype.every, predicate, values); | |||
|
|||
const assertType = (condition: boolean, description: string, value: unknown): asserts condition => { | |||
const assertType = (condition: boolean, description: string, value: unknown, options: { getValuesMessage?: () => string } = {}): asserts condition => { |
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 don't see the point in nesting it in an options object. We're only using this internally. Can just be a normal argument.
Does the issue also apply to |
@sindresorhus I tried a slightly different approach in my latest push and applied it to I decided to keep the options object for this approach because it's now a boolean flag. |
getValuesMessage
option for assertType
.all
and .any
Thanks :) |
This PR fixes #131
Approach: Add an options object to
assertType
. This allows a custom failure message from the calling code. It's a function that returns a string and passed in asgetValuesMessage
to the options object.What do you think of the approach?