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

assertFalse has wrong name #6166

Open
lionel-rowe opened this issue Nov 1, 2024 · 3 comments
Open

assertFalse has wrong name #6166

lionel-rowe opened this issue Nov 1, 2024 · 3 comments

Comments

@lionel-rowe
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Not sure what the prospects of changing this are given that assert is 1.x, but assertFalse has the wrong name (should be assertFalsy):

type Falsy = false | 0 | 0n | "" | null | undefined;
declare function assertFalse(expr: unknown, msg?: string): asserts expr is Falsy;

Describe the solution you'd like

Maybe rename to assertFalsy and deprecate assertFalse?

Describe alternatives you've considered

Do nothing

@kt3k
Copy link
Member

kt3k commented Nov 1, 2024

assertFalsy was also suggested when we first discussed this feature, but we decided on this name because there are many prior examples in other languages and libraries #2045

I personally think assertFalse is acceptable as it's conventional name in software ecosystem in general

@kt3k
Copy link
Member

kt3k commented Nov 1, 2024

There were also suggestions of renames like:

  • assertStrictEquals -> assertIs
  • assertEquals -> assertAlike

(I guess these are in similar direction)

But they didn't get much attention from the community #3513 (comment)

@lionel-rowe
Copy link
Contributor Author

From the examples in other languages/frameworks listed in #2045 (comment), it looks like all of them except Python's unittest strictly mean "false" rather than "falsy". Tbh doesn't seem like there's much utility in having functions that only check one specific value, given that assertEquals(val, false) works just as well. I think the only way such a function is useful at all is if it means "falsy", and even then that's only preferable over assert(!val) because it enables type narrowing in TS Actually, it looks looks like TS is now able to narrow on assert(!val), so maybe there's not much utility to this function regardless of exact semantics.

In any case, using "false" to mean "falsy" strikes me as confusing, especially given the precedent in other testing frameworks to include such strictly-equal-to-a-specific-value functions.

Happy to close this issue if the chances of changing it are slim-to-none.

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

No branches or pull requests

2 participants