Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a64e0b4
expect: stop toMatchObject/toMatchSnapshot from mutating the received…
robobun Jul 24, 2026
0c2c5b3
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 24, 2026
de76a02
address review: exception check after matchAsymmetricMatcher, preserv…
robobun Jul 24, 2026
bc40454
add array element case to the snapshot property-matcher test
robobun Jul 24, 2026
c04c920
substituteAsymmetricMatchers: skip non-plain objects, rewrite ancesto…
robobun Jul 25, 2026
965d7df
substituteAsymmetricMatchers: allocate clone before recursing, copy a…
robobun Jul 25, 2026
809865b
substituteAsymmetricMatchers: carry DontEnum attribute when shallow-c…
robobun Jul 25, 2026
d45cf16
snapshot substitution: record exactly what deepMatch checked
robobun Aug 13, 2026
359ecd6
trim comments in the substitution walker
robobun Aug 13, 2026
e73970a
snapshot substitution: clone events too, redirect copied references t…
robobun Aug 13, 2026
4aded9e
snapshot substitution: only put matchers on the clone, leave nested o…
robobun Aug 15, 2026
4574ec1
shorten two comments in the substitution walker
robobun Aug 15, 2026
f070c03
pin the snapshot shape of a shared object reached through an unwalked…
robobun Aug 15, 2026
66db71b
deepMatch: key the cycle guard on (object, subset) pairs
robobun Aug 15, 2026
4f1a622
snapshot substitution: throw RangeError instead of overflowing the st…
robobun Aug 24, 2026
e8602e3
drop the snapshot deep-chain test: deepMatch throws before the substi…
robobun Aug 24, 2026
234405d
ci: retrigger
robobun Aug 24, 2026
fe611a9
isAsymmetricMatcher: name the matcher classes through Bun::Bindgen::G…
robobun Oct 24, 2026
876c19a
expect: record matcher writes in deepMatch and undo them after printing
dylan-conway Oct 24, 2026
95a49de
expect: put the properties back when a termination ends the printing
robobun Oct 24, 2026
3720452
expect: register the property matcher cases with test.each
dylan-conway Oct 24, 2026
b7544f3
expect: keep hiding a matched element of a typed array or a Proxy
dylan-conway Oct 24, 2026
b499bc5
Merge branch 'main' into farm/da31bea9/fix-tomatchobject-mutation
dylan-conway Oct 31, 2026
870f2f6
Merge branch 'main' into farm/da31bea9/fix-tomatchobject-mutation
dylan-conway Oct 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions src/jsc/JSValue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2727,20 +2727,41 @@ impl JSValue {
}
/// `JSValue.jestDeepMatch` — `expect(a).toMatchObject(b)` /
/// snapshot-property-matcher subset comparison.
pub fn jest_deep_match(
/// If the result is `format_if` (`None`: either way), runs `format` with each matcher that passed put over the property it matched, then puts the properties back.
pub fn jest_deep_match<R, F: FnOnce(bool) -> JsResult<R>>(
self,
subset: JSValue,
global: &JSGlobalObject,
replace_props_with_asymmetric_matchers: bool,
) -> JsResult<bool> {
format_if: Option<bool>,
format: F,
) -> JsResult<Option<R>> {
struct Context<R, F> {
format: Option<F>,
result: Option<JsResult<R>>,
}
extern "C" fn call<R, F: FnOnce(bool) -> JsResult<R>>(ctx: *mut c_void, matched: bool) {
// SAFETY: `ctx` is the `Context<R, F>` below, which outlives the call and is not otherwise borrowed during it.
let ctx = unsafe { &mut *ctx.cast::<Context<R, F>>() };
if let Some(format) = ctx.format.take() {
ctx.result = Some(format(matched));
}
}
let mut ctx = Context {
format: Some(format),
result: None,
};
host_fn::from_js_host_call_generic(global, || {
JSC__JSValue__jestDeepMatch(
self,
subset,
global,
replace_props_with_asymmetric_matchers,
format_if != Some(false),
format_if != Some(true),
(&raw mut ctx).cast(),
call::<R, F>,
)
})
})?;
ctx.result.transpose()
}

// ── BigInt ordering. ────────────────────────────────
Expand Down Expand Up @@ -2851,7 +2872,10 @@ unsafe extern "C" {
this: JSValue,
subset: JSValue,
global: &JSGlobalObject,
replace_props: bool,
format_if_matched: bool,
format_if_not_matched: bool,
ctx: *mut c_void,
format: extern "C" fn(ctx: *mut c_void, matched: bool),
) -> bool;
safe fn JSC__JSValue__asBigIntCompare(this: JSValue, other: JSValue) -> ComparisonResult;
safe fn JSC__JSValue__keys(global: &JSGlobalObject, value: JSValue) -> JSValue;
Expand Down
2 changes: 1 addition & 1 deletion src/jsc/bindings/BunObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ JSC_DEFINE_HOST_FUNCTION(functionBunDeepMatch, (JSGlobalObject * globalObject, J
std::set<EncodedJSValue> objVisited;
std::set<EncodedJSValue> subsetVisited;
MarkedArgumentBuffer gcBuffer;
bool match = Bun__deepMatch</* enableAsymmetricMatchers */ false>(object, &objVisited, subset, &subsetVisited, globalObject, scope, &gcBuffer, false, false);
bool match = Bun__deepMatch</* enableAsymmetricMatchers */ false>(object, &objVisited, subset, &subsetVisited, globalObject, scope, &gcBuffer, nullptr, false);
RETURN_IF_EXCEPTION(scope, {});
return JSValue::encode(jsBoolean(match));
}
Expand Down
143 changes: 127 additions & 16 deletions src/jsc/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ template bool Bun__deepMatch<true>(
JSGlobalObject* globalObject,
ThrowScope& throwScope,
MarkedArgumentBuffer* gcBuffer,
bool replacePropsWithAsymmetricMatchers,
Bun::DeferredMatcherWrites* matcherWrites,
bool isMatchingObjectContaining);

template bool Bun__deepMatch<false>(
Expand All @@ -283,7 +283,7 @@ template bool Bun__deepMatch<false>(
JSGlobalObject* globalObject,
ThrowScope& throwScope,
MarkedArgumentBuffer* gcBuffer,
bool replacePropsWithAsymmetricMatchers,
Bun::DeferredMatcherWrites* matcherWrites,
bool isMatchingObjectContaining);

extern "C" bool Expect_readFlagsAndProcessPromise(JSC::EncodedJSValue instanceValue, JSC::JSGlobalObject* globalObject, ExpectFlags* flags, JSC::EncodedJSValue* value, AsymmetricMatcherConstructorType* constructorType);
Expand Down Expand Up @@ -577,7 +577,7 @@ AsymmetricMatcherResult matchAsymmetricMatcherAndGetFlags(JSGlobalObject* global
// SAFETY: visited property sets are not required when
// `enableAsymmetricMatchers` and `isMatchingObjectContaining`
// are both true
bool match = Bun__deepMatch<true>(otherProp, nullptr, patternObject, nullptr, globalObject, throwScope, nullptr, false, true);
bool match = Bun__deepMatch<true>(otherProp, nullptr, patternObject, nullptr, globalObject, throwScope, nullptr, nullptr, true);
RETURN_IF_EXCEPTION(throwScope, AsymmetricMatcherResult::FAIL);
if (match) {
return AsymmetricMatcherResult::PASS;
Expand Down Expand Up @@ -2222,6 +2222,34 @@ std::optional<bool> specialObjectsDequal(JSC::JSGlobalObject* globalObject, Mark
// only reached from `Bun.deepEquals(a, b, true, true)` in BunObject.cpp.
template bool Bun__deepEquals<true, false, false, true>(JSC::JSGlobalObject*, JSValue, JSValue, MarkedArgumentBuffer&, Vector<std::pair<JSC::JSValue, JSC::JSValue>, 16>&, ThrowScope&, bool);

// The properties `Bun__deepMatch` matched with an asymmetric matcher, which the snapshot and diff formatters print as that matcher.
class Bun::DeferredMatcherWrites {
WTF_FORBID_HEAP_ALLOCATION;

public:
void append(JSObject* target, const Identifier& key, JSValue matcher)
{
m_values.append(target);
m_values.append(matcher);
m_writes.append({ key });
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

// Puts each matcher over the property it matched, where the formatters read it.
void apply(JSGlobalObject*, ThrowScope&);
// Puts back what `apply` replaced.
void undo(JSGlobalObject*, ThrowScope&);

private:
struct Write {
Identifier key;
unsigned previousAttributes { 0 };
bool written { false };
};
Vector<Write, 4> m_writes;
MarkedArgumentBuffer m_values; // the (target, matcher) of each write
MarkedArgumentBuffer m_previousValues; // what each write replaced, empty if the target had no such property
};

/**
* @brief `Bun.deepMatch(a, b)`
*
Expand All @@ -2243,7 +2271,7 @@ template bool Bun__deepEquals<true, false, false, true>(JSC::JSGlobalObject*, JS
* @param globalObject
* @param throwScope
* @param gcBuffer
* @param replacePropsWithAsymmetricMatchers
* @param matcherWrites
* @param isMatchingObjectContaining
*
* @return true
Expand All @@ -2258,7 +2286,7 @@ bool Bun__deepMatch(
JSGlobalObject* globalObject,
ThrowScope& throwScope,
MarkedArgumentBuffer* gcBuffer,
bool replacePropsWithAsymmetricMatchers,
Bun::DeferredMatcherWrites* matcherWrites,
bool isMatchingObjectContaining)
{

Expand Down Expand Up @@ -2321,10 +2349,8 @@ bool Bun__deepMatch(
case AsymmetricMatcherResult::FAIL:
return false;
case AsymmetricMatcherResult::PASS:
if (replacePropsWithAsymmetricMatchers) {
obj->putDirectMayBeIndex(globalObject, property, subsetProp);
RETURN_IF_EXCEPTION(throwScope, false);
}
RETURN_IF_EXCEPTION(throwScope, false);
if (matcherWrites) matcherWrites->append(obj, property, subsetProp);
// continue to next subset prop
continue;
case AsymmetricMatcherResult::NOT_MATCHER:
Expand All @@ -2335,10 +2361,8 @@ bool Bun__deepMatch(
case AsymmetricMatcherResult::FAIL:
return false;
case AsymmetricMatcherResult::PASS:
if (replacePropsWithAsymmetricMatchers) {
subsetObj->putDirectMayBeIndex(globalObject, property, prop);
RETURN_IF_EXCEPTION(throwScope, false);
}
RETURN_IF_EXCEPTION(throwScope, false);
if (matcherWrites) matcherWrites->append(subsetObj, property, prop);
// continue to next subset prop
continue;
case AsymmetricMatcherResult::NOT_MATCHER:
Expand Down Expand Up @@ -2367,7 +2391,7 @@ bool Bun__deepMatch(
gcBuffer->append(subsetProp);
// property cycle detected
if (!didInsertProp.second || !didInsertSubset.second) continue;
bool matched = Bun__deepMatch<enableAsymmetricMatchers>(prop, seenObjProperties, subsetProp, seenSubsetProperties, globalObject, throwScope, gcBuffer, replacePropsWithAsymmetricMatchers, isMatchingObjectContaining);
bool matched = Bun__deepMatch<enableAsymmetricMatchers>(prop, seenObjProperties, subsetProp, seenSubsetProperties, globalObject, throwScope, gcBuffer, matcherWrites, isMatchingObjectContaining);
RETURN_IF_EXCEPTION(throwScope, false);
if (!matched) return false;
}
Expand All @@ -2381,6 +2405,73 @@ bool Bun__deepMatch(
return true;
}

// Reads the own property of `target` as it is stored. False if a direct put over it could not be undone.
static bool readReplaceableProperty(JSGlobalObject* globalObject, ThrowScope& scope, JSObject* target, const Identifier& key, JSValue& value, unsigned& attributes)
{
VM& vm = globalObject->vm();
if (std::optional<uint32_t> index = parseIndex(key)) {
JSC::JSType type = target->type();
// These keep their elements elsewhere, but take a put and take the element back. A BigInt array throws on a matcher.
bool asksClass = type == ProxyObjectType || (isTypedArrayType(type) && type != BigInt64ArrayType && type != BigUint64ArrayType);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟣 pre-existing, not blocking: nit, pre-existing: a Proxy whose target is a BigInt64Array or BigUint64Array still makes a passing index matcher throw a SyntaxError when the diff or snapshot is printed, as on the base branch. The BigInt exclusion in readReplaceableProperty at bindings.cpp:2367 only looks at target->type(), so a ProxyObjectType wrapper around a BigInt typed array is treated as writable and putDirectMayBeIndex at bindings.cpp:2392 forwards the matcher to the target's setIndex. Fix: refuse the write for every BigInt typed-array element however it is reached, e.g. unwrap Proxy targets (proxy->target(), repeated for nested proxies) before the BigInt type test, so the real element is printed instead of a throw.
A small fix can ride a push you are already making; otherwise a short reply is enough.

Why this was flagged

Trigger: expect(new Proxy(new BigInt64Array([1n]), {})).toMatchSnapshot({ 0: expect.any(BigInt) }), or the same received value through a failing toMatchObject. Bun__deepMatch passes the matcher (bindings.cpp:2300-2305) and appends (proxy, "0", matcher). In apply, readReplaceableProperty at bindings.cpp:2364-2375 sees type == ProxyObjectType, so asksClass is true, the forwarded getOwnPropertyDescriptor reports the element as an own data property, and the function returns true. putDirectMayBeIndex at bindings.cpp:2392 then goes through ProxyObject::defineOwnProperty to the BigInt64Array's defineOwnProperty, whose setIndex converts the matcher object with toBigInt, which throws a SyntaxError. RETURN_IF_EXCEPTION at 2393 aborts apply, format is skipped, and the SyntaxError is rethrown after undo, so a snapshot whose matchers all passed fails with that error. The direct BigInt64Array case is excluded by the same line and prints the element; the base branch threw for both direct and proxied arrays.

Verification: pre-existing (nit). readReplaceableProperty at src/jsc/bindings/bindings.cpp:2367 decides by target->type() alone; for a Proxy, type == ProxyObjectType short-circuits and the BigInt exclusion is never consulted. apply then runs target->putDirectMayBeIndex (line 2392), which reaches the target typed array's setIndex -> ToBigInt(matcher object), which throws SyntaxError. The base branch throws the same SyntaxError by the identical path.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stays as is: same throw by the same path on main, and a Proxy around a BigInt typed array with a matcher on one element is not what this PR is about.


Generated by Claude Code

PropertySlot slot(target, asksClass ? PropertySlot::InternalMethodType::GetOwnProperty : PropertySlot::InternalMethodType::VMInquiry, asksClass ? nullptr : &vm);
bool hasOwnProperty = asksClass ? target->methodTable()->getOwnPropertySlotByIndex(target, globalObject, *index, slot) : JSObject::getOwnPropertySlotByIndex(target, globalObject, *index, slot);
RETURN_IF_EXCEPTION(scope, false);
// A new element can grow an array.
if (!hasOwnProperty) return false;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
value = slot.isAccessor() ? JSValue(slot.getterSetter()) : slot.getValue(globalObject, *index);
attributes = slot.attributes();
return true;
}
value = target->getDirect(vm, key, attributes);
// A property the class implements natively, stored or still in its static table, cannot be put over another one.
return value ? !value.isCustomGetterSetter() : !target->hasNonReifiedStaticProperties() || !target->findPropertyHashEntry(key);
}

void Bun::DeferredMatcherWrites::apply(JSGlobalObject* globalObject, ThrowScope& scope)
{
for (size_t i = 0; i < m_writes.size(); i++) {
Write& write = m_writes[i];
JSObject* target = asObject(m_values.at(i * 2));
JSValue previous;
bool replaceable = readReplaceableProperty(globalObject, scope, target, write.key, previous, write.previousAttributes);
RETURN_IF_EXCEPTION(scope, );
m_previousValues.append(previous);
if (!replaceable) continue;
write.written = target->putDirectMayBeIndex(globalObject, write.key, m_values.at(i * 2 + 1));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
RETURN_IF_EXCEPTION(scope, );
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}

void Bun::DeferredMatcherWrites::undo(JSGlobalObject* globalObject, ThrowScope& scope)
{
JSC::Exception* failure = nullptr;
// Last first: two matchers can be written over one property.
for (size_t i = m_writes.size(); i--;) {
const Write& write = m_writes[i];
if (!write.written) continue;
JSObject* target = asObject(m_values.at(i * 2));
JSValue previous = m_previousValues.at(i);

if (!previous) {
DeletePropertySlot slot;
JSObject::deleteProperty(target, globalObject, write.key, slot);
} else if (previous.isGetterSetter())
target->putDirectAccessor(globalObject, write.key, uncheckedDowncast<GetterSetter>(previous), write.previousAttributes);
else if (std::optional<uint32_t> index = parseIndex(write.key))
target->putDirectIndex(globalObject, *index, previous, write.previousAttributes, PutDirectIndexLikePutDirect);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
else
target->putDirect(globalObject->vm(), write.key, previous, write.previousAttributes);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

// A Proxy trap can throw. The other properties are still put back.
if (JSC::Exception* exception = scope.exception()) [[unlikely]] {
if (!scope.tryClearException()) return;
if (!failure) failure = exception;
}
}
if (failure) [[unlikely]]
scope.throwException(globalObject, failure);
}

// anonymous namespace to avoid name collision
namespace {
template<bool isStrict, bool enableAsymmetricMatchers, bool checkPrototypes, bool skipPrototypeIdentity = false>
Expand Down Expand Up @@ -3341,7 +3432,7 @@ bool Bun__deepEqualsNodeStrictSkipProto(JSC::EncodedJSValue JSValue0, JSC::Encod

#undef IMPL_DEEP_EQUALS_WRAPPER

bool JSC__JSValue__jestDeepMatch(JSC::EncodedJSValue JSValue0, JSC::EncodedJSValue JSValue1, JSC::JSGlobalObject* globalObject, bool replacePropsWithAsymmetricMatchers)
bool JSC__JSValue__jestDeepMatch(JSC::EncodedJSValue JSValue0, JSC::EncodedJSValue JSValue1, JSC::JSGlobalObject* globalObject, bool formatIfMatched, bool formatIfNotMatched, void* ctx, void (*format)(void* ctx, bool matched))
{
JSValue obj = JSValue::decode(JSValue0);
JSValue subset = JSValue::decode(JSValue1);
Expand All @@ -3351,7 +3442,27 @@ bool JSC__JSValue__jestDeepMatch(JSC::EncodedJSValue JSValue0, JSC::EncodedJSVal
std::set<EncodedJSValue> objVisited;
std::set<EncodedJSValue> subsetVisited;
MarkedArgumentBuffer gcBuffer;
RELEASE_AND_RETURN(scope, Bun__deepMatch<true>(obj, &objVisited, subset, &subsetVisited, globalObject, scope, &gcBuffer, replacePropsWithAsymmetricMatchers, false));
Bun::DeferredMatcherWrites matcherWrites;
bool matched = Bun__deepMatch<true>(obj, &objVisited, subset, &subsetVisited, globalObject, scope, &gcBuffer, &matcherWrites, false);
RETURN_IF_EXCEPTION(scope, false);
if (!(matched ? formatIfMatched : formatIfNotMatched)) return matched;

matcherWrites.apply(globalObject, scope);
if (!scope.exception()) [[likely]]
format(ctx, matched);

{
// A termination cannot be cleared, and after a `node:vm` timeout the caller goes on. This holds it until the end of the block.
DeferTermination deferTermination(scope.vm());
// `undo` calls into JSC, which returns early while an exception is pending.
JSC::Exception* exception = scope.exception();
if (exception && !scope.tryClearException()) [[unlikely]]
exception = nullptr;
matcherWrites.undo(globalObject, scope);
if (exception && !scope.exception()) [[unlikely]]
scope.throwException(globalObject, exception);
Comment on lines +3455 to +3463

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 nit (optional): a Proxy whose defineProperty trap blocks while its element is put back hangs the test process, and a node:vm timeout or Worker.terminate() can no longer end it. undo reaches that trap through putDirectIndex at bindings.cpp:2413, and it runs inside the DeferTermination block at bindings.cpp:3333, which holds every termination request until the trap returns. Fix: keep user-code restores (index keys on ProxyObjectType targets, the only puts in undo that enter JS) outside the deferral, or let a termination that arrives during such a trap through and accept that the Proxy's own trap decided its element; the deferral is only needed for the puts that cannot run JS.

Why this was flagged

Trigger: expect(obj).toMatchObject({ list: { 0: expect.any(Number) }, missing: 1 }) or toMatchSnapshot where obj.list is a Proxy over an array with a defineProperty trap, run under vm.runInNewContext(..., { timeout }) (deadline armed at src/jsc/bindings/vm/NodeVMRunTermination.cpp:29) or inside a Worker that the parent terminates. apply writes the matcher through the trap at bindings.cpp:2392 (first define returns normally). After format, JSC__JSValue__jestDeepMatch constructs DeferTermination at bindings.cpp:3333 and calls undo; for the Proxy write undo calls target->putDirectIndex at bindings.cpp:2413, which goes through ProxyObject::defineOwnProperty and runs the user's defineProperty trap a second time. Because termination is deferred, a trap that loops (while (flag);) or blocks is never interrupted by the deadline: the request is only honoured when the block at 3332-3340 ends, which it never does. The base branch has no restore step, so the trap is never entered a second time and the deadline ends the script.

Verification: nit. JSC__JSValue__jestDeepMatch calls undo inside DeferTermination at bindings.cpp:3333. undo restores an index key with putDirectIndex (line 2413), the Proxy's user defineProperty trap. If the trap loops forever the block never ends and the termination never fires. On the base branch the Proxy write happened with no DeferTermination, so the same hanging trap was interruptible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stays as is. The path needs a defineProperty trap that returns on its first call and never on its second, on a Proxy of an array with a matcher on an element, under a node:vm timeout or worker.terminate(). Moving the Proxy restores out of the deferral would leave those elements holding matchers after any real timeout, because a trap cannot run with a termination pending. That is the hole the deferral closes, and it is the more likely of the two.


Generated by Claude Code

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
return matched;
}

extern "C" bool Bun__JSValue__isAsyncContextFrame(JSC::EncodedJSValue value)
Expand Down
8 changes: 6 additions & 2 deletions src/jsc/bindings/headers-handwritten.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ extern "C" void Bun__EventLoop__runCallback2(JSC::JSGlobalObject* global, JSC::E
template<bool isStrict, bool enableAsymmetricMatchers, bool checkPrototypes, bool skipPrototypeIdentity = false>
bool Bun__deepEquals(JSC::JSGlobalObject* globalObject, JSC::JSValue v1, JSC::JSValue v2, JSC::MarkedArgumentBuffer&, Vector<std::pair<JSC::JSValue, JSC::JSValue>, 16>& stack, JSC::ThrowScope& scope, bool addToStack);

namespace Bun {
class DeferredMatcherWrites;
}

/**
* @brief `Bun.deepMatch(a, b)`
*
Expand All @@ -473,7 +477,7 @@ bool Bun__deepEquals(JSC::JSGlobalObject* globalObject, JSC::JSValue v1, JSC::JS
* @param globalObject
* @param Scope
* @param gcBuffer
* @param replacePropsWithAsymmetricMatchers
* @param matcherWrites if not null, receives every property an asymmetric matcher passed on. Neither value is written to.
* @param isMatchingObjectContaining
*
* @return true
Expand All @@ -488,7 +492,7 @@ bool Bun__deepMatch(
JSC::JSGlobalObject* globalObject,
JSC::ThrowScope& throwScope,
JSC::MarkedArgumentBuffer* gcBuffer,
bool replacePropsWithAsymmetricMatchers,
Bun::DeferredMatcherWrites* matcherWrites,
bool isMatchingObjectContaining);

extern "C" void Bun__remapStackFramePositions(void*, ZigStackFrame*, size_t);
Expand Down
2 changes: 1 addition & 1 deletion src/jsc/bindings/headers.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions src/runtime/test_runner/expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,15 +1089,17 @@ impl Expect {
pretty_value: &mut impl bun_io::Write,
fn_name: &'static str,
) -> JsResult<()> {
if let Some(_prop_matchers) = property_matchers {
if !value.is_object() {
let signature = Self::get_signature(fn_name, "<green>properties<r><d>, <r>hint", false);
return throw!(self, global_this, signature, "\n\n<b>Matcher error: <red>received<r> values must be an object when the matcher has <green>properties<r>\n").map(drop);
}
let Some(prop_matchers) = property_matchers else {
return value.jest_snapshot_pretty_format(pretty_value, global_this);
};

let prop_matchers = _prop_matchers;
if !value.is_object() {
let signature = Self::get_signature(fn_name, "<green>properties<r><d>, <r>hint", false);
return throw!(self, global_this, signature, "\n\n<b>Matcher error: <red>received<r> values must be an object when the matcher has <green>properties<r>\n").map(drop);
}

if !value.jest_deep_match(prop_matchers, global_this, true)? {
value.jest_deep_match(prop_matchers, global_this, None, |matched| {
if !matched {
// TODO: print diff with properties from propertyMatchers
let signature = Self::get_signature(fn_name, "<green>propertyMatchers<r>", false);
let mut formatter = ConsoleObject::Formatter::new(global_this);
Expand All @@ -1107,9 +1109,9 @@ impl Expect {
value.to_fmt(&mut formatter),
).map(drop);
}
}

value.jest_snapshot_pretty_format(pretty_value, global_this)
value.jest_snapshot_pretty_format(pretty_value, global_this)
}).map(drop)
}

pub(crate) fn snapshot(
Expand Down
16 changes: 6 additions & 10 deletions src/runtime/test_runner/expect/toMatchObject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ impl Expect {
);
}

let mut pass = received_object.jest_deep_match(expected, global, true)?;

if not {
pass = !pass;
}
if pass {
// Under `.not` a match is the failure.
let Some(diff_formatter) = received_object.jest_deep_match(expected, global, Some(not), |_| {
DiffFormatter::new(global, received_object, expected, not)
})?
else {
return Ok(JSValue::UNDEFINED);
}

// handle failure
let diff_formatter = DiffFormatter::new(global, received_object, expected, not)?;
};

if not {
let signature: &str = get_signature("toMatchObject", "<green>expected<r>", true);
Expand Down
Loading
Loading