Skip to content

Commit

Permalink
Don't produce lines that only contains white space
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Jun 15, 2019
1 parent 6cadad1 commit 0c7124a
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 47 deletions.
28 changes: 18 additions & 10 deletions documentation/assertions/DOMElement/queried-for.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ expect(element, 'queried for first', '[data-test-id=emojies]', 'to satisfy', {

```output
expected
<section><h1>Numbers</h1><hr><ol data-test-id="numbers">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ol></section>
<section>
<h1>Numbers</h1>
<hr>
<ol data-test-id="numbers">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ol>
</section>
queried for first [data-test-id=emojies] to satisfy { children: expect.it('to have length', 666) }
The selector [data-test-id=emojies] yielded no results
```
Expand All @@ -64,11 +68,15 @@ expect(

```output
expected
<section><h1>Numbers</h1><hr><ol data-test-id="numbers">
<li>...</li>
<li>...</li>
<li>...</li>
</ol></section>
<section>
<h1>Numbers</h1>
<hr>
<ol data-test-id="numbers">
<li>...</li>
<li>...</li>
<li>...</li>
</ol>
</section>
queried for first [data-test-id=numbers] to have no children
expected
<ol data-test-id="numbers">
Expand Down
28 changes: 18 additions & 10 deletions documentation/assertions/DOMElement/to-contain-elements-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ expect(element, 'to contain elements matching', '[data-test-id=emojies]');

```output
expected
<section><h1>Numbers</h1><hr><ol data-test-id="numbers">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ol></section>
<section>
<h1>Numbers</h1>
<hr>
<ol data-test-id="numbers">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ol>
</section>
to contain elements matching '[data-test-id=emojies]'
```

Expand All @@ -47,11 +51,15 @@ expect(element, 'to contain no elements matching', 'li');

```output
expected
<section><h1>Numbers</h1><hr><ol data-test-id="numbers">
<li>...</li>
<li>...</li>
<li>...</li>
</ol></section>
<section>
<h1>Numbers</h1>
<hr>
<ol data-test-id="numbers">
<li>...</li>
<li>...</li>
<li>...</li>
</ol>
</section>
to contain no elements matching 'li'
NodeList[
Expand Down
14 changes: 9 additions & 5 deletions documentation/assertions/DOMNodeList/to-contain.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ expect(

```output
expected
<section><h1>Numbers</h1><hr><ol data-test-id="numbers">
<li class="number">...</li>
<li class="number">...</li>
<li class="number">...</li>
</ol></section>
<section>
<h1>Numbers</h1>
<hr>
<ol data-test-id="numbers">
<li class="number">...</li>
<li class="number">...</li>
<li class="number">...</li>
</ol>
</section>
queried for li to contain '<li class="count">Three</li>'
expected
NodeList[
Expand Down
28 changes: 18 additions & 10 deletions documentation/assertions/DOMNodeList/to-satisfy.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ expect(element, 'queried for', '[data-test-id=numbers] > li', 'to satisfy', [

```output
expected
<section><h1>Numbers</h1><hr><ol data-test-id="numbers">
<li class="number">...</li>
<li class="number">...</li>
<li class="number">...</li>
</ol></section>
<section>
<h1>Numbers</h1>
<hr>
<ol data-test-id="numbers">
<li class="number">...</li>
<li class="number">...</li>
<li class="number">...</li>
</ol>
</section>
queried for [data-test-id=numbers] > li to satisfy [ '<li>Three</li>', '<li>Two</li>', '<li>One</li>' ]
expected
NodeList[
Expand Down Expand Up @@ -86,11 +90,15 @@ expect(

```output
expected
<section><h1>Numbers</h1><hr><ol data-test-id="numbers">
<li class="number">...</li>
<li class="number">...</li>
<li class="number">...</li>
</ol></section>
<section>
<h1>Numbers</h1>
<hr>
<ol data-test-id="numbers">
<li class="number">...</li>
<li class="number">...</li>
<li class="number">...</li>
</ol>
</section>
queried for
[data-test-id=numbers] > li to exhaustively satisfy [
'<li class="number">One</li>',
Expand Down
19 changes: 12 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,20 +563,25 @@ module.exports = {
}

let width = startTag.length;
const multipleLines = inspectedChildren.some(o => {
const size = o.size();
const sizes = inspectedChildren.map(inspectedChild =>
inspectedChild.size()
);

const multipleLines = sizes.some(size => {
width += size.width;
return width > 60 || o.height > 1;
return width > 60 || size.height > 1;
});

if (multipleLines) {
output.nl().indentLines();

inspectedChildren.forEach((inspectedChild, index) => {
output
.i()
.block(inspectedChild)
.nl();
const childSize = sizes[index];
if (childSize.width > 0 && childSize.height > 0) {
output.i().block(inspectedChild);
}

output.nl();
});

output.outdentLines();
Expand Down
10 changes: 5 additions & 5 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3473,7 +3473,7 @@ describe('unexpected-dom', () => {
expected
<div>
<i>Hello</i>
<span class="name something-else">Jane Doe</span>
</div>
to contain <span class="name">John Doe</span>
Expand Down Expand Up @@ -3504,7 +3504,7 @@ describe('unexpected-dom', () => {
expected
<div>
<i>Hello</i>
<span class="name something-else">Jane Doe</span>
and
<div>John Doe</div>
Expand Down Expand Up @@ -3534,7 +3534,7 @@ describe('unexpected-dom', () => {
expected
<div>
<i>Hello</i>
<span class="name something-else"><em>...</em></span>
and
<div>John Doe</div>
Expand Down Expand Up @@ -3565,7 +3565,7 @@ describe('unexpected-dom', () => {
expected
<div>
<i>Hello</i>
<span class="name something-else" data-test-id="name">
Jane Doe
</span>
Expand Down Expand Up @@ -3720,7 +3720,7 @@ describe('unexpected-dom', () => {
expected
<div>
<i>Hello</i>
<span class="name something-else" data-test-id="name">
Jane Doe
</span>
Expand Down

0 comments on commit 0c7124a

Please sign in to comment.