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

[chai] add support for Set and Map to assert.lengthOf #66744

Merged
merged 2 commits into from Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions types/chai/chai-tests.ts
Expand Up @@ -1809,6 +1809,8 @@ suite("assert", () => {
assert.lengthOf("foobar", 6);
assert.lengthOf("foobar", 5);
assert.lengthOf({ length: 1 }, 5);
assert.lengthOf(new Set([1, 2, 3]), 3);
assert.lengthOf(new Map([['a', 1], ['b', 2], ['c', 3]]), 3);
});

test("match", () => {
Expand Down
6 changes: 5 additions & 1 deletion types/chai/index.d.ts
Expand Up @@ -1210,7 +1210,11 @@ declare namespace Chai {
* @param length Potential expected length of object.
* @param message Message to display on error.
*/
lengthOf<T extends { readonly length?: number | undefined }>(object: T, length: number, message?: string): void;
lengthOf<T extends { readonly length?: number | undefined } | { readonly size?: number | undefined }>(
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a new problem, but I don't understand why this is a generic at all. It could just accept this constraint as the parameter type.

That and, this type technically accepts the literal {} as an argument, which feels wrong.

object: T,
length: number,
message?: string,
): void;

/**
* Asserts that fn will throw an error.
Expand Down