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
We've been using power-assert with Lab (and Ava to some extend) since a while, and it's really a wonderful tool.
One of the few missing bits is the instrumentation of assert.throw().
Before even trying to contribute, I'd like first to validate with you that I'm taking the proper approach.
After few experiments, here is what I came up with.
Case 1
assert.throws(function(){/* whatever */});
Could be turned into:
var_rec1=new_PowerAssertRecorder1();_rec1.hasThrown=false;try{(function(){/* whatever */})();}catch(err){_rec1.hasThrown=true;}// check it has thrownassert(_rec1._expr(_rec1.hasThrown? true : !_rec1._capt('did not throw','arguments/0'),{content: 'assert.throws(function() {/* whatever */});',filepath: 'path/to/some_test.js',line: 1})/* , message*/);
When the asserted function doesn't throw, power-assert will report the following:
For the expectedsecond parameter, I'm not sure it worth any instrumentation, as the result will be logically the same.
As soon as the asserted function throws something, whether it comply with expected class/regexp/custom function or not, an AssertionError will be raised.
That's it, thanks for your time and feedback!
The text was updated successfully, but these errors were encountered:
@feugy Thank you for your comments! Instrumenting assert.throws is a bit difficult task to wrestle with, There may be some edge cases to consider carefully. I'll review your implementation plans and also show you what's I'm thinking. Let's make it happen together.
Hello!
We've been using power-assert with Lab (and Ava to some extend) since a while, and it's really a wonderful tool.
One of the few missing bits is the instrumentation of
assert.throw()
.Before even trying to contribute, I'd like first to validate with you that I'm taking the proper approach.
After few experiments, here is what I came up with.
Case 1
Could be turned into:
When the asserted function doesn't throw, power-assert will report the following:
assert.throws(block, [expected], [message])
also have a message argument which, if present, should be reported when the asserted didn't throw.Case 2
Could be turned into:
When the asserted function thrown object with unexpected class, power-assert will report the following:
Case 3
Could be turned into:
When the asserted function thrown value which doesn't match regexp, power-assert will report the following:
Case 4
Could be turned into:
When the asserted function thrown value that doesn't pass custom function, power-assert will report the following:
Case 5
For
doesNotThrow()
, it could be slightly simpler:Could be turned into:
Which will produce on unexpected error:
For the
expected
second parameter, I'm not sure it worth any instrumentation, as the result will be logically the same.As soon as the asserted function throws something, whether it comply with expected class/regexp/custom function or not, an AssertionError will be raised.
That's it, thanks for your time and feedback!
The text was updated successfully, but these errors were encountered: