Search code examples
jestjstddts-jest

Is there a way to make jest's error report show expected and received one after the other in addition to the diff view?


My limited brain sometimes has trouble interpreting diffs of arrays of trees of nodes.

I find out outputs from jest like the following to be hard to understand:

Error: expect(received).toEqual(expected) // deep equality

- Expected  - 0
+ Received  + 5

@@ -1,10 +1,15 @@
  Array [
    Object {
      "children": Array [
        Object {
          "children": Array [],
+         "textValue": "",
+         "type": Symbol(WHITESPACE),
+       },
+       Object {
+         "children": Array [],
          "textValue": "Suivie d'une ligne de texte.",
          "type": Symbol(TEXT),
        },
      ],
      "textValue": "Une introduction",

I do understand them, but that's not a natural representation for me and causes me a lot of effort.

Is there a way to tell jest to report deep-equality checks failures with a diff and / or also showing the full received object and the full expected object side by side ?

When the objects are not too big, my ideal error report would be:

  1. full expected representation
  2. full received representation
  3. diff representation

My current workaround when I can't wrap my head around a diff is to use the debugger, but it would be nice if I could avoid this step.


Solution

  • As mentioned in a comment to the question, there's a command-line argument --expand that does more or less that.

    It does not separate out the expected vs received presentation, but the diff presentation includes the entire context (all lines before and after the affected ones).