sassoftware/jsl-hamcrest

Trivial assertions result in "Expression Failure" message

Closed this issue · 1 comments

ut test( "Simple Pass", "One equals one", Expr(
	ut assert that( Expr(1), ut equal to(1) );
));

ut test( "Simple Pass", "dog equals dog", Expr(
	ut assert that( Expr("dog"), ut equal to("dog") );
));

The trivial test cases shown above result in an "Expression Failure" message

This, unfortunately, is expected behavior and is a result of the check at Core.jsl#L52-L66. This is meant to force the user to wrap their test expr in Expr. In JSL, wrapping a number or string literal in Expr does not change its type and it will not pass the Is Expr test. If we allow literals here, we will have no way to distinguish between your example above and a more complicated expression that evaluated to a number or string at the callsite. The latter could potentially throw and is what we are trying to protect against.

You can use ut as expr or ut assert value to work around this issue.