-
-
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
Changes from 6 commits
345b512
03d4426
7830f37
2712b64
9f3283b
e437baf
ec6c4ce
413f007
b2ebe6f
6e401c9
7ad3f7c
e84a67b
3a985ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,3 +168,21 @@ test('array.ofType', t => { | |
ow(['foo', 'b'], 'foo', ow.array.ofType(ow.string.minLength(3))); | ||
}, '(array `foo`) Expected string to have a minimum length of `3`, got `b`'); | ||
}); | ||
|
||
test('array.exactShape', t => { | ||
t.notThrows(() => { | ||
ow(['🦄', 2, 3, true, {isFirstCommit: true}], ow.array.exactShape([ow.string, ow.number, ow.number, ow.boolean, ow.object.exactShape({isFirstCommit: ow.boolean})])); | ||
}); | ||
|
||
t.throws(() => { | ||
ow(['🦄', 2, 'nope', true, {isFirstCommit: true}], ow.array.exactShape([ow.string, ow.number, ow.number, ow.boolean, ow.object.exactShape({isFirstCommit: ow.string})])); | ||
}, 'Expected property `2` to be of type `number` but received type `string` in array'); | ||
sindresorhus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
t.throws(() => { | ||
ow(['🦄', 'nope', {isFirstCommit: true}], ow.array.exactShape([ow.string, ow.string, ow.object.exactShape({isFirstCommit: ow.boolean}), ow.number, ow.boolean])); | ||
}, 'Expected property `3` to be of type `number` but received type `undefined` in array'); | ||
|
||
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 commentThe 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 commentThe 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 |
||
}); |
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.