summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2022-08-31 21:14:34 +0100
committerMichael Williamson <mike@zwobble.org>2022-08-31 21:14:34 +0100
commitd67ddaff3c05da19012a1daff584a0f33ff5df83 (patch)
tree2cb803d48a27d0bfd1cc2b38d6ec504ffec8e90e /test
parent93eb38471f6a992df68bbc75a19d4703bf3f64a2 (diff)
Test mammoth.images.imgElement directly
Diffstat (limited to 'test')
-rw-r--r--test/images.tests.js55
1 files changed, 54 insertions, 1 deletions
diff --git a/test/images.tests.js b/test/images.tests.js
index a66cdee..9a9344d 100644
--- a/test/images.tests.js
+++ b/test/images.tests.js
@@ -3,6 +3,7 @@ var assert = require("assert");
var hamjest = require("hamjest");
var assertThat = hamjest.assertThat;
var contains = hamjest.contains;
+var equalTo = hamjest.equalTo;
var hasProperties = hamjest.hasProperties;
var mammoth = require("../");
@@ -25,10 +26,62 @@ test('mammoth.images.dataUri() encodes images in base64', function() {
},
contentType: "image/jpeg"
});
-
+
return mammoth.images.dataUri(image).then(function(result) {
assertThat(result, contains(
hasProperties({tag: hasProperties({attributes: {"src": "data:image/jpeg;base64,YWJj"}})})
));
});
});
+
+
+test('mammoth.images.imgElement()', {
+ 'when element does not have alt text then alt attribute is not set': function() {
+ var imageBuffer = new Buffer("abc");
+ var image = new documents.Image({
+ readImage: function(encoding) {
+ return promises.when(imageBuffer.toString(encoding));
+ },
+ contentType: "image/jpeg"
+ });
+
+ var result = mammoth.images.imgElement(function(image) {
+ return {src: "<src>"};
+ })(image);
+
+ return result.then(function(result) {
+ assertThat(result, contains(
+ hasProperties({
+ tag: hasProperties({
+ attributes: equalTo({src: "<src>"})
+ })
+ })
+ ));
+ });
+ },
+
+ 'when element has alt text then alt attribute is set': function() {
+ var imageBuffer = new Buffer("abc");
+ var image = new documents.Image({
+ readImage: function(encoding) {
+ return promises.when(imageBuffer.toString(encoding));
+ },
+ contentType: "image/jpeg",
+ altText: "<alt>"
+ });
+
+ var result = mammoth.images.imgElement(function(image) {
+ return {src: "<src>"};
+ })(image);
+
+ return result.then(function(result) {
+ assertThat(result, contains(
+ hasProperties({
+ tag: hasProperties({
+ attributes: equalTo({alt: "<alt>", src: "<src>"})
+ })
+ })
+ ));
+ });
+ }
+});