question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

assert.throws Doesn't Count Towards Assertions

See original GitHub issue

Describe 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: image

Network tab: image

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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
SethFalcocommented, Mar 4, 2021

We could probably close this issue since you have already finished the task.

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.

1reaction
SethFalcocommented, Mar 4, 2021

Have you tried doing something like this?

expect(() => solver.solve(puzzleString)).toThrow('Puzzle cannot be solved');

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found