This is an automated email from the ASF dual-hosted git repository.

gerben pushed a commit to branch dom-tests
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git

commit f9008da04636a54d95120f9f498a43e5c2bfcb20
Author: Gerben <[email protected]>
AuthorDate: Fri May 22 14:21:21 2020 +0200

    Make reporting of failed tests more readable.
---
 packages/dom/test/text-quote-match.ts | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/packages/dom/test/text-quote-match.ts 
b/packages/dom/test/text-quote-match.ts
index e348dbe..ac5b13a 100644
--- a/packages/dom/test/text-quote-match.ts
+++ b/packages/dom/test/text-quote-match.ts
@@ -305,12 +305,18 @@ async function testMatcher(
   assert.equal(matches.length, expected.length);
   matches.forEach((match, i) => {
     const expectedRange = expected[i];
-    assert.include(match, {
-      startContainer: evaluateXPath(doc, expectedRange.startContainerXPath),
-      startOffset: expectedRange.startOffset,
-      endContainer: evaluateXPath(doc, expectedRange.endContainerXPath),
-      endOffset: expectedRange.endOffset,
-    });
+    const expectedStartContainer = evaluateXPath(doc, 
expectedRange.startContainerXPath);
+    const expectedEndContainer = evaluateXPath(doc, 
expectedRange.endContainerXPath);
+    assert(match.startContainer === expectedStartContainer,
+      `unexpected start container: ${prettyNodeName(match.startContainer)}; `
+      + `expected ${prettyNodeName(expectedStartContainer)}`
+    );
+    assert.equal(match.startOffset, expectedRange.startOffset);
+    assert(match.endContainer === evaluateXPath(doc, 
expectedRange.endContainerXPath),
+      `unexpected end container: ${prettyNodeName(match.endContainer)}; `
+      + `expected ${prettyNodeName(expectedEndContainer)}`
+    );
+    assert.equal(match.endOffset, expectedRange.endOffset);
   });
 }
 
@@ -322,3 +328,15 @@ function evaluateXPath(doc: Document, xpath: string): Node 
{
   );
   return nodes[0];
 }
+
+function prettyNodeName(node: Node) {
+  switch (node.nodeType) {
+    case Node.TEXT_NODE:
+      const text = (node as Text).nodeValue;
+      return `#text "${text.length > 50 ? text.substring(0, 50) + '…' : 
text}"`;
+    case Node.ELEMENT_NODE:
+      return `<${(node as Element).tagName.toLowerCase()}>`;
+    default:
+      return node.nodeName.toLowerCase();
+  }
+}

Reply via email to