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

Expect allows "empty" assertions #940

Closed
Weeknie opened this issue Mar 6, 2017 · 1 comment
Closed

Expect allows "empty" assertions #940

Weeknie opened this issue Mar 6, 2017 · 1 comment

Comments

@Weeknie
Copy link

Weeknie commented Mar 6, 2017

When defining assertions, there seems to be no error thrown if the final word in the chain doesn't define an actual assertion. E.g. expect(42).to.be.cthulu doesn't seem to do anything, it will simply silently disappear into the night.

Whenever someone starts a line with expect(), you can be certain it's supposed to be an assertion, so if by the end of the statement no assertion has been defined, shouldn't this throw some kind of unexpected error?

I am rather new to chai, so if there's a specific reason for this or this is hard to implement, you'll have to forgive me :) I mostly suggest fixing behavior because it helps to detect typos or wrongly assumed assertion names (I tried debugging chai-as-promised's expect(promise).resolved for an hour before figuring out it was supposed to be expect(promise).fulfilled

@meeber
Copy link
Contributor

meeber commented Mar 6, 2017

@Weeknie Thanks for reaching out. I'm going to close this issue simply because it's a duplicate of existing issues, but please feel free to jump in on the discussion in #726. Another issue worth reading is #94.

The short answer is that some of the problems such as typos can be easily fixed (and already are in v4 available via chai@canary), but the overall issue of empty assertions sneaking by undetected cannot be easily fixed. It'd require tight integration between test runner (e.g., Mocha) and assertion library (e.g., Chai), and even then would present challenges related to Chai's bdd interfaces, since a single expect can lead to multiple assertions that are on a single line or even branch multiple times across multiple lines.

@meeber meeber closed this as completed Mar 6, 2017
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