-
-
Notifications
You must be signed in to change notification settings - Fork 693
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
chai doesn't catch an error has thrown #1414
Comments
@MakariukVl Can you provide a minimum viable code that reproduces the issue? |
Yes of course @koddsson, I will attach the code. The quickSort function should cause an error in line 24 if the input array is an object array. The error itself is called, test No16 (line 209) must verify this, but chai doesn't catch this error. Another similar test No15 passed. quicksort.js
quicksort.test.js
|
Hey there, I was experiencing a similar situation. This basic example should run the tests as expected without exiting. // someFunction.js
export default function someFunction(arg) {
if (!arg) {
throw new Error("Oops")
}
} and testfile: import "chai/register-should.js"
import someFunction from "./someFunction.js"
describe("someFunction()", function functionName() {
it("should throw without arguments", function () {
someFunction.should.throw()
})
it("should not throw with an argument", function () {
(()=> someFunction("argument")).should.not.throw()
})
}) You should pay attention to catching errors in your other tests and code usage where you use / instanciate a function that throws errors on wrong usage. If you don't, testing will exit with the actual error thrown. In my situation I was instanciating someFunction without arguments in another describe block, like: // describe block
const value = someFunction() which caused my tests to stop running due to thrown error. In your case the code exits because somewhere you throw an error when an array with objects is passed: throw new TypeError("Default compare function for arrays of objects is not supported"); Due to quickSort being a kind of recursive function calling quickSort again with different arguments might cause your tests to exit. It did not throw the error with first call, but quickSort got called again internally which threw the error that did not get caught. So your test did not pass or fail. Should |
this is my test
which fails with the message:
but other similar test passed:
I couldn't find any explanations / solutions / workarounds for this, so I think it's a bug with the
expect(x).to.throw
assertion.The text was updated successfully, but these errors were encountered: