snapshot icon indicating copy to clipboard operation
snapshot copied to clipboard

fix: snapshot all top level siblings of passed JQuery subjects

Open stuartlong opened this issue 5 years ago • 3 comments

Fixes issue #23. When serializes DOM or react elements, instead of taking the first element of the passed JQuery object, we iterate through all top level elements and concatonate the serializations. So when serializing this dom:

<p>1</p>
<p>2</p>
<p>3<p>

The current JSON output is

"1": {
    "tagName": "p",
    "childNodes": [
      {
        "nodeName": "#text",
        "nodeValue": "1"
      }
    ]
  }

and the current HTML output is

"1": "<p>1</p>"

Not that the last two p tags are missing from the snapshots.

With this fix the JSON output becomes:

"1": [
  {
    "tagName": "p",
    "childNodes": [
      {
        "nodeName": "#text",
        "nodeValue": "1"
      }
    ]
  },
  {
    "tagName": "p",
    "childNodes": [
      {
        "nodeName": "#text",
        "nodeValue": "2"
      }
    ]
  },
  {
    "tagName": "p",
    "childNodes": [
      {
        "nodeName": "#text",
        "nodeValue": "3"
      }
    ]
  }
]

and the HTML output:

"1": "<p>1</p><p>2</p><p>3</p>"

stuartlong avatar Apr 09 '19 16:04 stuartlong

@bahmutov for review

stuartlong avatar Apr 09 '19 16:04 stuartlong

this is good @stuartlong but we need a demo test showing that this has been fixed. A simple index.html with an element and a snapshot should be enough to confirm

bahmutov avatar Apr 26 '19 21:04 bahmutov

Running into this right now! Any chance this PR could be finished up? 🙏

mxstbr avatar Nov 26 '20 14:11 mxstbr