assert.throws Doesn't Count Towards Assertions
See original GitHub issueDescribe your problem and how to reproduce it: I was working on the Sudoku Solver project and ran into an issue with my tests failing despite my unit tests passing locally.
Test case:
test('Invalid puzzle strings fail the solver', (done) => {
const puzzleString = '115..2.84..63.12.7.2..5.....9..1....8.2.3674.3.7.2..9.47...8..1..16....926914.37.';
assert.throws(() => solver.solve(puzzleString), 'Puzzle cannot be solved');
done();
});
Unit tests:
Network tab:
I can see in the tests for the project, it dictates all tests must have at least one assertion. I do have an assertion though, but it’s not being returned.
Add a Link to the page with the problem: https://www.freecodecamp.org/learn/quality-assurance/quality-assurance-projects/sudoku-solver
Tell us about your browser and operating system:
- Browser Name: Firefox
- Browser Version: 86.0 (64-bit)
- Operating System: Ubuntu 20.04.2 LTS x86_64
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to test that no exception is thrown? - java - Stack Overflow
A JUnit test is judged to have failed if it throws any exception other than an expected exception. Usually no exceptions are expected....
Read more >API Reference - Chai Assertion Library
Asserts that value is an object of type 'Object' (as revealed by Object.prototype.toString ). The assertion does not match subclassed objects.
Read more >Assert.Throws | NUnit Docs
The Assert.Throws method is pretty much in a class by itself. Rather than comparing values, it attempts to invoke a code snippet, represented...
Read more >Asserts - Node Tap
You can also use any Error-throwing assertion library, including Node.js's built-in assert module. A throw fails a test, so not-throwing passes.
Read more >JUnit Test Exception Examples - How to assert an exception is ...
You put the code that can throw exception in the execute() method of an Executable type - Executable is a functional interface defined...
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 Free
Top 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
No, because this is still a valid issue. I could work around it for now, however others will still encounter it when they shouldn’t, and it still needs to be fixed.
I’ve already passed the task so I don’t need to work around it anymore. However, I did try
expect(() => solver.solve(puzzleString)).throw('Puzzle cannot be solved');
anyway.This did not fix the issue. I’m betting it’s probably something to do with the pattern not catching the
() =>
syntax as a valid assertion, but haven’t looked into it much yet.