aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-09-02 21:47:03 +0100
committerMichael Williamson <mike@zwobble.org>2016-09-02 21:47:03 +0100
commitab00f9ab421f1547c6a0ff7e4f3ad4bbcc94a9c0 (patch)
tree448e42529ef788947a37332aa87d8436e5be6d7a
parent4b47a9a5208442a3eea8f72eb6c9ebe1647de91c (diff)
Use hamjest for tidier image assertions
-rw-r--r--package.json3
-rw-r--r--test/docx/body-reader.tests.js57
2 files changed, 44 insertions, 16 deletions
diff --git a/package.json b/package.json
index 74d3644..3dc9d5f 100644
--- a/package.json
+++ b/package.json
@@ -33,7 +33,8 @@
"duck": "~0.1.11",
"uglify-js": "~2.4.8",
"temp": "~0.7.0",
- "eslint": "2.13.1"
+ "eslint": "2.13.1",
+ "hamjest": "2.13.0"
},
"browser": {
"./lib/unzip.js": "./browser/unzip.js",
diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js
index 6471ec6..fccb264 100644
--- a/test/docx/body-reader.tests.js
+++ b/test/docx/body-reader.tests.js
@@ -1,6 +1,14 @@
var assert = require("assert");
var path = require("path");
+var _ = require("underscore");
+var hamjest = require("hamjest");
+var promiseThat = hamjest.promiseThat;
+var allOf = hamjest.allOf;
+var hasProperties = hamjest.hasProperties;
+var willBe = hamjest.willBe;
+var FeatureMatcher = hamjest.FeatureMatcher;
+
var BodyReader = require("../../lib/docx/body-reader").BodyReader;
var documents = require("../../lib/documents");
var xml = require("../../lib/xml");
@@ -395,6 +403,16 @@ test('_GoBack bookmark is ignored', function() {
});
var IMAGE_BUFFER = new Buffer("Not an image at all!");
+var IMAGE_RELATIONSHIP_ID = "rId5";
+
+function isImage(options) {
+ return allOf(
+ hasProperties(_.omit(options, "buffer")),
+ new FeatureMatcher(willBe(options.buffer), "buffer", "buffer", function(element) {
+ return element.read();
+ })
+ );
+}
test("can read imagedata elements with r:id attribute", function() {
var imagedataElement = new XmlElement("v:imagedata", {"r:id": "rId5", "o:title": "It's a hat"});
@@ -408,10 +426,12 @@ test("can read imagedata elements with r:id attribute", function() {
"word/media/hat.png": IMAGE_BUFFER
})
});
- assert.equal("image", element.type);
- assert.equal(element.altText, "It's a hat");
- assert.equal(element.contentType, "image/png");
- return assertImageBuffer(element, IMAGE_BUFFER);
+ return promiseThat(element, isImage({
+ type: "image",
+ altText: "It's a hat",
+ contentType: "image/png",
+ buffer: IMAGE_BUFFER
+ }));
});
test("can read inline pictures", function() {
@@ -429,10 +449,12 @@ test("can read inline pictures", function() {
"word/media/hat.png": IMAGE_BUFFER
})
}));
- assert.equal("image", element.type);
- assert.equal(element.altText, "It's a hat");
- assert.equal(element.contentType, "image/png");
- return assertImageBuffer(element, IMAGE_BUFFER);
+ return promiseThat(element, isImage({
+ type: "image",
+ altText: "It's a hat",
+ contentType: "image/png",
+ buffer: IMAGE_BUFFER
+ }));
});
test("can read anchored pictures", function() {
@@ -460,9 +482,12 @@ test("can read anchored pictures", function() {
"word/media/hat.png": IMAGE_BUFFER
})
}));
- assert.equal("image", element.type);
- assert.equal(element.altText, "It's a hat");
- return assertImageBuffer(element, IMAGE_BUFFER);
+ return promiseThat(element, isImage({
+ type: "image",
+ altText: "It's a hat",
+ contentType: "image/png",
+ buffer: IMAGE_BUFFER
+ }));
});
test("can read linked pictures", function() {
@@ -480,10 +505,12 @@ test("can read linked pictures", function() {
"file:///media/hat.png": IMAGE_BUFFER
})
}));
- assert.equal("image", element.type);
- assert.equal(element.altText, "It's a hat");
- assert.equal(element.contentType, "image/png");
- return assertImageBuffer(element, IMAGE_BUFFER);
+ return promiseThat(element, isImage({
+ type: "image",
+ altText: "It's a hat",
+ contentType: "image/png",
+ buffer: IMAGE_BUFFER
+ }));
});
test("warning if unsupported image type", function() {