From 98f7720fe6e41beb5c97ebdc9fcabcfdd5f2985a Mon Sep 17 00:00:00 2001 From: MathioLucas <162763121+MathioLucas@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:16:32 -0500 Subject: [PATCH] Update toBe.lua (#14) 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. --- libs/jestronaut/expect/matchers/toBe.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/jestronaut/expect/matchers/toBe.lua b/libs/jestronaut/expect/matchers/toBe.lua index cc93d37..51ae9aa 100644 --- a/libs/jestronaut/expect/matchers/toBe.lua +++ b/libs/jestronaut/expect/matchers/toBe.lua @@ -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