Asserting that assertions were made
See original GitHub issueIs there a way to assert whether any chai assertions have been made?
We’ve been bitten a number of times by tests passing gloriously in Mocha, only to realize that it’s because no assertions were made for whatever reason (a common one is the misspelling of assertions, such as calledwith
instead of calledWith
. This would easily be caught by having a test hook that runs after each test to make sure that assertions were indeed made. It won’t help with situations where some assertions are made and others are broken by misspelling or such, but in our experience it’s been less common (if occurring at all.)
If not possible, I’m happy to contribute, just let me know!
Issue Analytics
- State:
- Created 11 years ago
- Reactions:1
- Comments:35 (12 by maintainers)
Top Results From Across the Web
Assertion - Stanford Encyclopedia of Philosophy
We make assertions to share information, coordinate our actions, defend arguments, and communicate our beliefs and desires.
Read more >Programming With Assertions - Oracle Help Center
An assertion is a statement in the Java programming language that enables you to test your assumptions about your program. For example, if...
Read more >Python's assert: Debug and Test Your Code Like a Pro
Assertions are a convenient tool for documenting, debugging, and testing code during development. Once you've debugged and tested your code with ...
Read more >How can you assert an assertion was done - Stack Overflow
We catch the error and assertTrue(true) to state that it was ok. But we can'T assert that the assertion passed in any reasonnable...
Read more >Assertions | Cypress Documentation
Cypress bundles the popular Chai assertion library, as well as helpful extensions ... These chainers are available for BDD assertions ( expect /...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, jest has an expect.assertions method that verifies that a certain number of assertions are called during a test. I was hoping there was a chai equivalent to this. I’ve been searching in google and couldn’t find anything so far.
It seems this feature was not actually implemented. At least I didn’t find anything neither in the documentation nor in the tests showing how to do it. In my application we use the
assert
interface, so here is how I implemented it:in
src/test/util/chai-extensions.js
:In the tests: