@@ -3,6 +3,7 @@ var assert = require("assert");
33var hamjest = require ( "hamjest" ) ;
44var assertThat = hamjest . assertThat ;
55var contains = hamjest . contains ;
6+ var equalTo = hamjest . equalTo ;
67var hasProperties = hamjest . hasProperties ;
78
89var mammoth = require ( "../" ) ;
@@ -25,10 +26,62 @@ test('mammoth.images.dataUri() encodes images in base64', function() {
2526 } ,
2627 contentType : "image/jpeg"
2728 } ) ;
28-
29+
2930 return mammoth . images . dataUri ( image ) . then ( function ( result ) {
3031 assertThat ( result , contains (
3132 hasProperties ( { tag : hasProperties ( { attributes : { "src" : "data:image/jpeg;base64,YWJj" } } ) } )
3233 ) ) ;
3334 } ) ;
3435} ) ;
36+
37+
38+ test ( 'mammoth.images.imgElement()' , {
39+ 'when element does not have alt text then alt attribute is not set' : function ( ) {
40+ var imageBuffer = new Buffer ( "abc" ) ;
41+ var image = new documents . Image ( {
42+ readImage : function ( encoding ) {
43+ return promises . when ( imageBuffer . toString ( encoding ) ) ;
44+ } ,
45+ contentType : "image/jpeg"
46+ } ) ;
47+
48+ var result = mammoth . images . imgElement ( function ( image ) {
49+ return { src : "<src>" } ;
50+ } ) ( image ) ;
51+
52+ return result . then ( function ( result ) {
53+ assertThat ( result , contains (
54+ hasProperties ( {
55+ tag : hasProperties ( {
56+ attributes : equalTo ( { src : "<src>" } )
57+ } )
58+ } )
59+ ) ) ;
60+ } ) ;
61+ } ,
62+
63+ 'when element has alt text then alt attribute is set' : function ( ) {
64+ var imageBuffer = new Buffer ( "abc" ) ;
65+ var image = new documents . Image ( {
66+ readImage : function ( encoding ) {
67+ return promises . when ( imageBuffer . toString ( encoding ) ) ;
68+ } ,
69+ contentType : "image/jpeg" ,
70+ altText : "<alt>"
71+ } ) ;
72+
73+ var result = mammoth . images . imgElement ( function ( image ) {
74+ return { src : "<src>" } ;
75+ } ) ( image ) ;
76+
77+ return result . then ( function ( result ) {
78+ assertThat ( result , contains (
79+ hasProperties ( {
80+ tag : hasProperties ( {
81+ attributes : equalTo ( { alt : "<alt>" , src : "<src>" } )
82+ } )
83+ } )
84+ ) ) ;
85+ } ) ;
86+ }
87+ } ) ;
0 commit comments