Skip to content

Fantom: a toMatchInlineSnapshot() call that several tests reach is written with one of their values, where Jest refuses it #60591

Backlog

Description

@YevheniiKotyrlo

Description

I found this while reading how Fantom writes inline snapshots, with test.each tables in mind, whose rows all reach the one toMatchInlineSnapshot() call in their body.

When several tests reach one toMatchInlineSnapshot() call with different values, Fantom keeps one pending snapshot per line, the last one winning (runner/snapshotUtils.js L234-L247), and writes that value into the call. The next run fails each test that reached it with another value, and -u writes one of those values back. Jest refuses such a call, failing the run with "Jest: Multiple inline snapshots for the same call are not supported."

Steps to reproduce

  1. Clone the reproducer below and run ./fantom/reproduce.sh inline-snapshot-shared. It needs only Docker: it clones react/react-native at main, builds Fantom's tester with yarn workspace @react-native/fantom build using Clang and LLD 23.1.3, with two settings the reproducer adds for that Clang (-Wno-error=deprecated-literal-operator, and SKCMS_NO_RUNTIME_CPU_DETECTION for Skia's skcms), copies fantom/InlineSnapshotShared-itest.js into private/react-native-fantom/src/__tests__/ and runs yarn fantom --ci=false on it, then again, then with -u, printing the call after the first and the last run:
[…]
function check(value) {
  expect(value).toMatchInlineSnapshot();
}

test('a', () => {
  check('a');
});

test('b', () => {
  check('b');
});

Expected: the first run fails, as Jest's does, and leaves the call unwritten.

Actual: the first run passes and writes b's value into the call, the second run fails a, -u writes a's value, and the script exits 1:

[…]
react-native eb37db0c4448a7d26684a5d8b4027166c13fc3e2, committed 2026-12-05T08:30:53+00:00
[…]
== the first run
[…]
PASS fantom private/react-native-fantom/src/__tests__/InlineSnapshotShared-itest.js (6.681 s)
  InlineSnapshotShared (hermes)
    ✓ a (5 ms)
    ✓ b
[…]
Tests:       2 passed, 2 total
Snapshots:   2 written, 2 passed, 4 total
[…]
yarn fantom exited with status 0
== the call after the first run:  expect(value).toMatchInlineSnapshot(`"b"`);
== the second run
[…]
FAIL fantom private/react-native-fantom/src/__tests__/InlineSnapshotShared-itest.js
  InlineSnapshotShared (hermes)
    ✕ a (12 ms)
    ✓ b
[…]
Tests:       1 failed, 1 passed, 2 total
Snapshots:   1 failed, 1 passed, 2 total
[…]
yarn fantom exited with status 1
== the third run, with -u
[…]
Tests:       2 passed, 2 total
Snapshots:   1 updated, 1 passed, 2 total
[…]
yarn fantom exited with status 0
== the call after the third run:  expect(value).toMatchInlineSnapshot(`"a"`);
SUMMARY: the first run passes and writes test b's value into the call, so the second run fails test a; -u then writes:  expect(value).toMatchInlineSnapshot(`"a"`);

React Native Version

main at eb37db0; 0.88.1 writes inline snapshots the same way

Affected Platforms

Other (please specify): Fantom, yarn fantom

Output of npx @react-native-community/cli info

Not applicable: Fantom runs from a checkout of this repository. The reproducer builds and runs it in the reactnativecommunity/react-native-android image with clang version 23.1.3.

Stacktrace or Logs

[…]
  ● InlineSnapshotShared (hermes) › a

    Expected to match inline snapshot.
    - Expected
    + Received

    - "b"
    + "a"
[…]
    >  7 |   expect(value).toMatchInlineSnapshot(`"b"`);
         |                                      ^
[…]

MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/react-native-fantom-reproducer

Screenshots and Videos

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions