Skip to content

Commit

Permalink
Leave the children as-is when converting an element to a satisfy spec
Browse files Browse the repository at this point in the history
Improves the output in a number of cases and fixes #294
  • Loading branch information
papandreou committed Oct 26, 2019
1 parent 11d2ea8 commit a39bfa7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,7 @@ module.exports = {
: node.attributes[i].value || '';
}
}
result.children = Array.prototype.map.call(node.childNodes, childNode =>
convertDOMNodeToSatisfySpec(childNode, isHtml)
);
result.children = Array.prototype.slice.call(node.childNodes);
return result;
} else if (node.nodeType === 3) {
// DOMTextNode
Expand Down
22 changes: 11 additions & 11 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ describe('unexpected-dom', () => {
NodeList[
<div>
foo // should equal 'quux'
foo // should equal quux
//
// -foo
// +quux
Expand Down Expand Up @@ -1790,7 +1790,7 @@ describe('unexpected-dom', () => {
NodeList[
<div>
foo // should equal 'quux'
foo // should equal quux
//
// -foo
// +quux
Expand Down Expand Up @@ -1856,7 +1856,7 @@ describe('unexpected-dom', () => {
NodeList[
<div foo="bar">
foo // should equal 'foo!'
foo // should equal foo!
//
// -foo
// +foo!
Expand Down Expand Up @@ -2107,7 +2107,7 @@ describe('unexpected-dom', () => {
expected <div foo="bar" baz="quux">foobar</div> to satisfy <div foo="bar" baz="quux">hey</div>
<div foo="bar" baz="quux">
foobar // should equal 'hey'
foobar // should equal hey
//
// -foobar
// +hey
Expand Down Expand Up @@ -2222,7 +2222,7 @@ describe('unexpected-dom', () => {
<div
style="border-left-color: #FFF" // expected <div style="border-left-color: #FFF">hey</div>
// to satisfy { name: 'div', attributes: { style: 'border-left-color: #FFFF;' }, children: [ 'hey' ] }
// to satisfy { name: 'div', attributes: { style: 'border-left-color: #FFFF;' }, children: [ hey ] }
// Expectation contains invalid styles: 'border-left-color: #FFFF'
>hey</div>
`
Expand All @@ -2243,7 +2243,7 @@ describe('unexpected-dom', () => {
<div
style="width: 120px" // expected <div style="width: 120px">hey</div>
// to satisfy { name: 'div', attributes: { style: 'color;background;width: 120px' }, children: [ 'hey' ] }
// to satisfy { name: 'div', attributes: { style: 'color;background;width: 120px' }, children: [ hey ] }
// Expectation contains invalid styles: 'color;background'
>hey</div>
`
Expand Down Expand Up @@ -3600,7 +3600,7 @@ describe('unexpected-dom', () => {
to contain <span><span>Hello</span><!--ignore--></span>
<span>
// missing { name: 'span', attributes: {}, children: [ 'Hello' ] }
// missing <span>Hello</span>
Hello
</span>
`
Expand Down Expand Up @@ -3648,7 +3648,7 @@ describe('unexpected-dom', () => {
to contain <span class="name">John Doe</span>
<span class="name something-else">
Jane Doe // should equal 'John Doe'
Jane Doe // should equal John Doe
//
// -Jane Doe
// +John Doe
Expand Down Expand Up @@ -3744,7 +3744,7 @@ describe('unexpected-dom', () => {
to contain <span data-test-id="name">John Doe</span>
<span class="name something-else" data-test-id="name">
Jane Doe // should equal 'John Doe'
Jane Doe // should equal John Doe
//
// -Jane Doe
// +John Doe
Expand All @@ -3767,7 +3767,7 @@ describe('unexpected-dom', () => {
expected <div><span></span></div> to contain <span><i>Hello</i></span>
<span>
// missing { name: 'i', attributes: {}, children: [ 'Hello' ] }
// missing <i>Hello</i>
</span>
`
);
Expand Down Expand Up @@ -3812,7 +3812,7 @@ describe('unexpected-dom', () => {
<span>
<strong>Hello</strong>
<em>world</em>
// missing '!'
// missing !
</span>
`
);
Expand Down

0 comments on commit a39bfa7

Please sign in to comment.