aboutsummaryrefslogtreecommitdiff
path: root/test/document-to-html.tests.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-08-28 20:03:00 +0100
committerMichael Williamson <mike@zwobble.org>2016-08-28 20:03:00 +0100
commitd333cee1c7a7f95cadf5b59e8dbb0124d73852df (patch)
treef837b57e640eb9bad909416c6822f6edb9d192ac /test/document-to-html.tests.js
parentb1ae23f544c479d2b71347bbf67df7baac40d78f (diff)
Add test explicitly for image error handling
Diffstat (limited to 'test/document-to-html.tests.js')
-rw-r--r--test/document-to-html.tests.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/document-to-html.tests.js b/test/document-to-html.tests.js
index cc8aff5..59eba49 100644
--- a/test/document-to-html.tests.js
+++ b/test/document-to-html.tests.js
@@ -590,6 +590,28 @@ test('can add custom handler for images', function() {
});
});
+test('when custom image handler throws error then error is stored in error message', function() {
+ var error = new Error("Failed to convert image");
+ var image = new documents.Image({
+ readImage: function(encoding) {
+ return promises.when(new Buffer().toString(encoding));
+ },
+ contentType: "image/png"
+ });
+ var converter = new DocumentConverter({
+ convertImage: function(element, messages) {
+ throw error;
+ }
+ });
+ return converter.convertToHtml(image).then(function(result) {
+ assert.equal(result.value, '');
+ assert.equal(result.messages.length, 1);
+ var message = result.messages[0];
+ assert.equal("error", message.type);
+ assert.equal("Failed to convert image", message.message);
+ });
+});
+
test('long documents do not cause stack overflow', function() {
var paragraphs = [];
for (var i = 0; i < 1000; i++) {