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

Add array.exactShape predicate #187

Merged
merged 13 commits into from
Jan 19, 2021

Conversation

ilkerceng
Copy link
Contributor

@ilkerceng ilkerceng commented Sep 15, 2020

exactShape implementation for array.

Fixes #179

@sindresorhus sindresorhus changed the title Fix for #179 Add array.exactShape predicate Sep 30, 2020
test/array.ts Outdated Show resolved Hide resolved
/**
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.
Copy link
Owner

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.

@sindresorhus
Copy link
Owner

#187 (comment)

@ilkerceng
Copy link
Contributor Author

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');
Copy link
Owner

@sindresorhus sindresorhus Dec 19, 2020

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.

Copy link
Contributor Author

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

/**
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.
Copy link
Owner

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.

Copy link
Contributor Author

@ilkerceng ilkerceng Dec 26, 2020

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.


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sounds better.

Copy link
Contributor Author

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.


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.
Copy link
Owner

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.

@sindresorhus sindresorhus merged commit dbef144 into sindresorhus:master Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tuple types in Ow?
2 participants