From 0459e2cf53ad8670e6692020f5864eafffe2caf9 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 18 Feb 2024 10:51:56 +0000 Subject: Improve error message when failing to find the body element in a document --- test/docx/document-xml-reader.tests.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/docx/document-xml-reader.tests.js') diff --git a/test/docx/document-xml-reader.tests.js b/test/docx/document-xml-reader.tests.js index 08389e1..10c8df1 100644 --- a/test/docx/document-xml-reader.tests.js +++ b/test/docx/document-xml-reader.tests.js @@ -23,3 +23,17 @@ test("when body element is present then body is read", function() { {} )); }); + +test("when body element is not present then error is thrown", function() { + var bodyReader = createBodyReaderForTests({}); + var documentXmlReader = new DocumentXmlReader({ + bodyReader: bodyReader + }); + var paragraphXml = xml.element("w:p", {}, []); + var bodyXml = xml.element("w:body2", {}, [paragraphXml]); + var documentXml = xml.element("w:document", {}, [bodyXml]); + + assert.throws(function() { + documentXmlReader.convertXmlToDocument(documentXml); + }, /Could not find the body element: are you sure this is a docx file?/); +}); -- cgit v1.2.3