Open fynnfluegge opened 1 year ago
@fynnfluegge,
I usually don't care about the error message that is thrown:
// So I would us:
assertThrows(() => {
str.fromJson(Json 123);
});
// In your example, you can use:
assertThrows(() => {
str.fromJson(Json 123);
}, expectedErrorMessage: PARSE_ERROR);
The last argument in this case is AssertThrowOptions struct
that has expectedErrorMessage: str?
field and if it is missing it shouldn't assert that message at all
// So I would us: assertThrows(() => { str.fromJson(Json 123); }); // In your example, you can use: assertThrows(() => { str.fromJson(Json 123); }, expectedErrorMessage: PARSE_ERROR);
The last argument in this case is
AssertThrowOptions struct
that hasexpectedErrorMessage: str?
field and if it is missing it shouldn't assert that message at all
Alright but how to use this inisde test "fromJson" { }
?
This try ... catch
would pass if there is no exception
Alright but how to use this inisde test "fromJson" { }? This try ... catch would pass if there is no exception I think that because It excepts an exception it should fail if exception is not thrown:
a possible implementation of this is
inflight assertThrows (code: inflight ():void, options: AssertThrowOptions) {
try {
code();
assert(false); // fail in case exception is not thrown
} catch {
// verify exception message
}
}
inflight assertThrows (code: inflight ():void, options: AssertThrowOptions) { try { code(); assert(false); // fail in case exception is not thrown } catch { // verify exception message } }
Nice 👍 So, would make sense to adapt this to any test in the sdkTests
and remove this try .. catch
right?
Yes, makes sense to me.
Hi,
This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
Hi,
This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
@tsuf239, @Chriscbr, @skorfmann - would it make sense to add expect.throws(e)
to our builtin expect
module and use that instead of duplicating the assertThrows
function code and the older try .. catch
anti-pattern across the SDK spec tests?
@tsuf239, @Chriscbr, @skorfmann - would it make sense to add
expect.throws(e)
to our builtinexpect
module and use that instead of duplicating theassertThrows
function code and the oldertry .. catch
anti-pattern across the SDK spec tests?
yes! but it would have to be expect(() => statement).throws(e)
or expect.throws(() => statement, e)
Hi,
This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
Hi,
This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
Feature Spec
examples/tests/sdk_tests
are usingtry ... catch
in wingtest { }
code block. Should beassertThrows
instead, since assert is only called on exception catch and ignored otherwise.Use Cases
Tests ensure that the exception is thrown with the correct error message.
Implementation Notes
Using predefined
assertThrows
method fails with:Component
SDK
Community Notes