Skip to content

Conversation

@thecp
Copy link

@thecp thecp commented Dec 19, 2021

Prior to this change expected and received data structures were printed
via using the JSON.stringify method to console. However this method is
limited by the fact that it doesn't support enhanced data types like Map,
Set, etc. except when using a replacer function.

Prior to this change expected and received data structures were printed
via using the JSON.stringify method to console. However this method is
limited by the fact that it doesn't support enhanced data types like Map,
Set, etc. except when using a replacer function.
@brandonroberts
Copy link
Member

Thanks @thecp. Will you provide a snippet of what the changes would look like? Would like to see if its worth bringing in the extra dependency.

@thecp
Copy link
Author

thecp commented Feb 5, 2022

Hey Brandon, sure. Consider following example. You have a map (new Map([['name', 'Christoph']])) and you'd expect a different map (new Map([['name', 'John']])) instead.

With the old output you cannot see what is the problem as expected and received look exactly the same:

    Expected: (b|),
    Received: (?|),
        
    Expected:
    [{"frame":0,"notification":{"kind":"N","value":{}}},{"frame":0,"notification":{"kind":"C"}}]
        
    Received:
    [{"frame":0,"notification":{"kind":"N","value":{}}},{"frame":0,"notification":{"kind":"C"}}]

Whereas with the new output you actually see the difference now:

    Expected: (b|),
    Received: (?|),
        
    Expected:
    Array [
      Object {
        "frame": 0,
        "notification": Object {
          "error": undefined,
          "kind": "N",
          "value": Map {
            "name" => "John",
          },
        },
      },
      Object {
        "frame": 0,
        "notification": Object {
          "error": undefined,
          "kind": "C",
          "value": undefined,
        },
      },
    ]
        
    Received:
    Array [
      Object {
        "frame": 0,
        "notification": Object {
          "error": undefined,
          "kind": "N",
          "value": Map {
            "name" => "Christoph",
          },
        },
      },
      Object {
        "frame": 0,
        "notification": Object {
          "error": undefined,
          "kind": "C",
          "value": undefined,
        },
      },
    ]

Although the output is a bit bloated now, this is a big plus from a user perspective to really see what's causing the test to fail. I stumbled over this too, wasting a couple of hours looking for the issue...

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants