Skip to content

Commit

Permalink
Update toBe.lua (#14)
Browse files Browse the repository at this point in the history
Fix: Allow :toBe(nil) to succeed when actual and expected are both nil

- Updated the toBe matcher to handle nil values properly.
- Added a special condition to check for both actual and expected being nil.
  • Loading branch information
MathioLucas authored Dec 4, 2024
1 parent b0f319c commit 98f7720
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libs/jestronaut/expect/matchers/toBe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
local function toBe(expect, expected)
local actual = expect.actual

-- Special case: both actual and expected are nil
if actual == nil and expected == nil then
return true
end

if not expect:checkEquals(actual, expected) then
error("Expected " .. tostring(actual) .. (expect.inverse and " not " or "") .. " to be " .. tostring(expected))
end
Expand Down

0 comments on commit 98f7720

Please sign in to comment.