Testing matchers

Jest Matcher Playground

Paste received and expected JSON, choose a Jest-style matcher and inspect PASS/FAIL, diff rows and explanation without sending examples to a backend.

  • Input stays in the browser
  • Expected vs received diff
  • No regex execution

Compare matcher behavior

Use curated presets or paste JSON values to check matcher semantics before writing a test or reviewing an assertion.

FAIL

Two identical object literals fail identity matching but pass deep equality. Object.is identity semantics for primitives; separate JSON objects are not the same reference.

Assertion input

Matcher result

FAIL: expect(received).toBe failed.

Matcher
toBe
Received
object
Expected
object
Nodes
14
expect(received).toBe({"id":"release-42","flags":["search","adsense"],"meta":{"stable":true}});
Changed$

Expected: {"id":"release-42","flags":["search","adsense"],"meta":{"stable":true}}

Received: {"id":"release-42","flags":["search","adsense"],"meta":{"stable":true}}

What matcher reviews usually miss

Identity is not structure

toBe is right for primitives and references, but copied object literals usually need toEqual or toStrictEqual. Seeing both outcomes side by side makes assertion intent easier to review.

Partial matches are contracts

toMatchObject is useful when the test cares about a subset of a response. The diff focuses on missing or changed expected keys instead of distracting reviewers with unrelated fields.

Public examples need guardrails

The playground avoids executing JavaScript or regex, blocks prototype-pollution keys and keeps examples within size limits so it remains a safe public review surface.

Matcher choices sit next to lint rules, parser output, configuration and schema validation. These tools cover the adjacent review steps.

FAQ

Is this running Jest in the browser?

No. It is a focused matcher explainer that mirrors common Jest-style semantics for JSON values. It does not execute a test runner or arbitrary JavaScript.

How do I represent undefined or NaN in JSON?

Use {"$pfType":"undefined"} or {"$pfType":"NaN"}. Those sentinels keep the input JSON-only while still covering important matcher cases.

Why does toMatch not support regex here?

The public MVP uses plain substring matching to avoid ReDoS and execution complexity. Regex behavior should be confirmed in the repository test suite.

Is pasted data stored?

No. Evaluation runs in the browser for this playground. The MVP does not add accounts, history, remote fetch or backend execution.