Repository: unexpectedjs/unexpected
Pull request #534 (2018-11-17 19:28:56)

Fix the output to make the unexpected-dom test suite pass
I'll make a follow-up PR that ensures that the rest of the amend handling is correct.


Patch:
diff --git a/lib/assertions.js b/lib/assertions.js
index 3c9565ab..03fca2b7 100644
--- a/lib/assertions.js
+++ b/lib/assertions.js
@@ -474,7 +474,7 @@ module.exports = expect => {
                     output
                       .i()
                       .block(function() {
-                        this.amend(propertyOutput).amend(delimiterOutput);
+                        this.append(propertyOutput).amend(delimiterOutput);
                         if (!keyInValue[key]) {
                           this.sp().annotationBlock(function() {
                             this.error('should be removed');
@@ -1711,7 +1711,7 @@ module.exports = expect => {
                             );
 
                             this.append(propertyOutput)
-                              .append(delimiterOutput)
+                              .amend(delimiterOutput)
                               .sp()
                               .error('// should be moved');
                           } else if (type === 'insert') {
@@ -1754,11 +1754,11 @@ module.exports = expect => {
                             this.block(function() {
                               if (type === 'remove') {
                                 this.append(propertyOutput)
-                                  .append(delimiterOutput)
+                                  .amend(delimiterOutput)
                                   .sp()
                                   .error('// should be removed');
                               } else if (type === 'equal') {
-                                this.append(propertyOutput).append(
+                                this.append(propertyOutput).amend(
                                   delimiterOutput
                                 );
                               } else {
@@ -1773,12 +1773,10 @@ module.exports = expect => {
                                     output: output.clone()
                                   });
                                 if (valueDiff && valueDiff.inline) {
-                                  this.append(valueDiff).append(
-                                    delimiterOutput
-                                  );
+                                  this.append(valueDiff).amend(delimiterOutput);
                                 } else {
                                   this.append(propertyOutput)
-                                    .append(delimiterOutput)
+                                    .amend(delimiterOutput)
                                     .sp()
                                     .annotationBlock(function() {
                                       this.omitSubject = diffItem.value;


Test patch:
diff --git a/test/assertions/to-satisfy.spec.js b/test/assertions/to-satisfy.spec.js
index 9273ea8b..44c14490 100644
--- a/test/assertions/to-satisfy.spec.js
+++ b/test/assertions/to-satisfy.spec.js
@@ -1346,6 +1346,89 @@ describe('to satisfy assertion', () => {
           ']'
       );
     });
+
+    it('handles multi-line items correctly', () => {
+      class Box {
+        constructor(value) {
+          this.value = value;
+        }
+      }
+
+      const clonedExpect = expect.clone().addType({
+        name: 'box',
+        identify: value => value && value instanceof Box,
+        inspect: (box, depth, output, inspect) =>
+          output.block(output => {
+            output.text('╔═══╗').nl();
+            output.text(`║ ${box.value} ║`).nl();
+            output.text('╚═══╝');
+          }),
+        equal: (a, b, equal) => a.value === b.value
+      });
+
+      expect(
+        () => {
+          clonedExpect(
+            [new Box(0), new Box(1), new Box(2), new Box(4), new Box(3)],
+            'to satisfy',
+            [new Box(1), new Box(0), new Box(2), new Box(3)]
+          );
+        },
+        'to throw',
+        `\
+        expected
+        [
+          ╔═══╗
+          ║ 0 ║
+          ╚═══╝,
+          ╔═══╗
+          ║ 1 ║
+          ╚═══╝,
+          ╔═══╗
+          ║ 2 ║
+          ╚═══╝,
+          ╔═══╗
+          ║ 4 ║
+          ╚═══╝,
+          ╔═══╗
+          ║ 3 ║
+          ╚═══╝
+        ]
+        to satisfy
+        [
+          ╔═══╗
+          ║ 1 ║
+          ╚═══╝,
+          ╔═══╗
+          ║ 0 ║
+          ╚═══╝,
+          ╔═══╗
+          ║ 2 ║
+          ╚═══╝,
+          ╔═══╗
+          ║ 3 ║
+          ╚═══╝
+        ]
+
+        [
+          ╔═══╗  // should equal ╔═══╗
+          ║ 0 ║  //              ║ 1 ║
+          ╚═══╝, //              ╚═══╝
+          ╔═══╗  // should equal ╔═══╗
+          ║ 1 ║  //              ║ 0 ║
+          ╚═══╝, //              ╚═══╝
+          ╔═══╗
+          ║ 2 ║
+          ╚═══╝,
+          ╔═══╗  // should equal ╔═══╗
+          ║ 4 ║  //              ║ 3 ║
+          ╚═══╝, //              ╚═══╝
+          ╔═══╗ // should be removed
+          ║ 3 ║
+          ╚═══╝
+        ]`.replace(/^        /gm, '')
+      );
+    });
   });
 
   it('should render a missing item expected to satisfy an expect.it', () => {