You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the TypeScript declarations the property function of property allows to return void. The documentation and the JSDoc right above it say it should return true or false, so this is a bit of an inconsistency.
Unfortunate this results in some unexpected behaviour when using the throws assertion from chai. In this example I'm explicitly not using mocha-testcheck, despite working in a mocha workspace, partially to properly show the issue, but also because no TypeScript declarations exist for that package yet.
The property function at (1) is an arrow function returning the result of chai.assert.throws which is void. According to the TypeScript declarations this is absolutely valid.
The tested function at (2) throws an error and therefore confirms the assertion at (1).
Expected behaviour
The checkResult.result at (3) should be true since the assertion was successful and the property function completed. Actual behaviour
The checkResult.result at (3) contains an Error and the assertion fails.
Additional information
The arrow function returning void work perfectly fine with any of my other assertions, but throws seems to have some issues.
Solutions
Easiest would be to remove the void return type from the TypeScript declarations, although this might break some code and removes the ability to create simple property arrow function and requires us to change the arrow function at (1) to return true at the end of it:
According to the TypeScript declarations the property function of
property
allows to returnvoid
. The documentation and the JSDoc right above it say it should returntrue
orfalse
, so this is a bit of an inconsistency.testcheck-js/type-definitions/testcheck.d.ts
Lines 182 to 185 in c7dce07
Unfortunate this results in some unexpected behaviour when using the
throws
assertion from chai. In this example I'm explicitly not usingmocha-testcheck
, despite working in a mocha workspace, partially to properly show the issue, but also because no TypeScript declarations exist for that package yet.The property function at (1) is an arrow function returning the result of
chai.assert.throws
which isvoid
. According to the TypeScript declarations this is absolutely valid.The tested function at (2) throws an error and therefore confirms the assertion at (1).
Expected behaviour
The
checkResult.result
at (3) should betrue
since the assertion was successful and the property function completed.Actual behaviour
The
checkResult.result
at (3) contains an Error and the assertion fails.Additional information
The arrow function returning
void
work perfectly fine with any of my other assertions, butthrows
seems to have some issues.Solutions
Easiest would be to remove the
void
return type from the TypeScript declarations, although this might break some code and removes the ability to create simple property arrow function and requires us to change the arrow function at (1) toreturn true
at the end of it:Alternatively testcheck could interpret
undefined
returned by theproperty
function just like it would do withtrue
.The text was updated successfully, but these errors were encountered: