Skip to content

Show a clearer diff for asymmetric matcher test results #9046

@huan

Description

@huan

Clear and concise description of the problem

When using asymmetric matchers, the output is very hard to read - it always takes me a few minutes and need to add more log code to figure out which part is actually unexpected.

Error: AssertionError: expected { …(3) } to match object { model: StringMatching{…}, …(2) }

- Expected
+ Received

@@ -1,23 +1,20 @@
  {
-   "instances": ArrayContaining [
-     ObjectContaining {
-       "prompt": StringMatching /^(?=.*walking)(?=.*together)(?=.*park).*/i,
-       "referenceImages": ArrayContaining [
-         ObjectContaining {
-           "image": ObjectContaining {
-             "gcsUri": StringContaining "person1.jpg",
+   "instances": [
+     {
+       "image": {
+         "gcsUri": "gs://example/person1.jpg",
          "mimeType": "image/jpeg",
        },
-           "referenceType": StringMatching /^(asset|style)$/,
-         },
-         ObjectContaining {
-           "image": ObjectContaining {
-             "gcsUri": StringContaining "person2.png",
+       "prompt": "A park scene with two figures walking together",
+       "referenceImages": [
+         {
+           "image": {
+             "gcsUri": "gs://example/person2.png",
              "mimeType": "image/png",
            },
-           "referenceType": StringMatching /^(asset|style)$/,
+           "referenceType": "asset",
          },
        ],
      },
    ],
    "model": StringMatching /^veo-3\.1-(fast-)?generate-preview$/,

 ❯ src/assisted-mode/assisted-mode.test.ts:31:34

Any plan to improve it?

Suggested solution

It would be great if we can have a diff like this:

    expected: {
      model: expect.stringMatching(/^veo-3\.1-(fast-)?generate-preview$/),
      instances: expect.arrayContaining([
        expect.objectContaining({
          // AI consolidates both subject assets into referenceImages[] and may synthesize a cleaned prompt.
-           prompt: expect.stringMatching(/^(?=.*walking)(?=.*together)(?=.*park).*/i),
+           prompt: 'walk',
          referenceImages: expect.arrayContaining([
            expect.objectContaining({
              image: expect.objectContaining({
                gcsUri: expect.stringContaining("person1.jpg"),
-                 mimeType: "image/jpeg",
+                 mimeType: "image/png",
              }),
              referenceType: expect.stringMatching(/^(asset|style)$/),
            }),
            expect.objectContaining({
              image: expect.objectContaining({
-                 gcsUri: expect.stringContaining("person2.png"),
+                 gcsUri: "person.jpg",
                mimeType: "image/png",
              }),
              referenceType: expect.stringMatching(/^(asset|style)$/),
            }),
          ]),
        }),
      ]),
      parameters: expect.objectContaining({
-         durationSeconds: expect.any(Number),
+         durationSeconds: "8",
        aspectRatio: "16:9",
        generateAudio: expect.any(Boolean),
      }),
    },

Alternative

No response

Additional context

I have a lot fixtures like this and it's a hard time to debug them.

Validations

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions