Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nabetti1720 committed Nov 12, 2024
1 parent aac2b2e commit 2d223bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
10 changes: 8 additions & 2 deletions modules/llrt_assert/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ fn ok(ctx: Ctx, value: Value, message: Opt<Value>) -> Result<()> {
return Ok(());
}
},
Type::Array | Type::Object => {
Type::Array
| Type::BigInt
| Type::Constructor
| Type::Exception
| Type::Function
| Type::Symbol
| Type::Object => {
return Ok(());
},
_ => {},
Expand All @@ -43,7 +49,7 @@ fn ok(ctx: Ctx, value: Value, message: Opt<Value>) -> Result<()> {

Err(Exception::throw_message(
&ctx,
"The expression was evaluated to a falsy value",
"AssertionError: The expression was evaluated to a falsy value",
))
}

Expand Down
19 changes: 13 additions & 6 deletions tests/unit/assert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ import assert from "assert";

describe("assert.ok", () => {
it("Should be returned 'undefined' (So it's not an error)", () => {
expect(assert.ok(true)).toBeUndefined();
expect(assert.ok(1)).toBeUndefined();
expect(assert.ok("non-empty string")).toBeUndefined();
expect(assert.ok([])).toBeUndefined();
expect(assert.ok({})).toBeUndefined();
expect(assert.ok(true)).toBeUndefined(); //bool
expect(assert.ok(1)).toBeUndefined(); // numeric
expect(assert.ok("non-empty string")).toBeUndefined(); // string
expect(assert.ok([])).toBeUndefined(); // array
expect(assert.ok({})).toBeUndefined(); // object
expect(assert.ok(() => {})).toBeUndefined(); // function
expect(assert.ok(123n)).toBeUndefined(); // bigint
expect(assert.ok(Symbol())).toBeUndefined(); // symbol
expect(assert.ok(new Error())).toBeUndefined(); // error
class AssertTestClass {}
expect(assert.ok(AssertTestClass)).toBeUndefined(); // constructor
});

it("Should be returned exception", () => {
const errMsg = "The expression was evaluated to a falsy value";
const errMsg =
"AssertionError: The expression was evaluated to a falsy value";
try {
assert.ok(false);
} catch (err) {
Expand Down

0 comments on commit 2d223bf

Please sign in to comment.