diff --git a/src/path.js b/src/path.js index 60d6ade0..88c4e959 100644 --- a/src/path.js +++ b/src/path.js @@ -608,7 +608,7 @@ Path.prototype.toSVG = function(options, pathData) { let svg = ''; assert.equal(path.toSVG({optimize: true}), expectedResult); - // we can't test toDOMElement() in node context! + assert.equal(path.toDOMElement({optimize: true}).getAttribute('d'), expectedPath); }); it('should calculate flipY from bounding box if set to true', function() { @@ -97,4 +120,41 @@ describe('path.js', function() { const path = Path.fromSVG(inputPath, { x: 1, y: 2, scale: 2.5 }); assert.equal(path.toPathData(), expectedPath); }); + + it('should apply fill and stroke for toSVG()', function() { + assert.equal(emptyPath.toSVG(), ''); + emptyPath.fill = '#ffaa00'; + assert.equal(emptyPath.toSVG(), ''); + emptyPath.stroke = '#0000ff'; + assert.equal(emptyPath.toSVG(), ''); + emptyPath.strokeWidth = 2; + assert.equal(emptyPath.toSVG(), ''); + emptyPath.fill = null; + assert.equal(emptyPath.toSVG(), ''); + emptyPath.fill = 'black'; + assert.equal(emptyPath.toSVG(), ''); + }); + + it('should apply fill and stroke for toDOMElement()', function() { + // in browser context these wouldn't be undefined, but we're only mocking it + assert.equal(emptyPath.toDOMElement().getAttribute('fill'), undefined); + assert.equal(emptyPath.toDOMElement().getAttribute('stroke'), undefined); + assert.equal(emptyPath.toDOMElement().getAttribute('stroke-width'), undefined); + + emptyPath.fill = '#ffaa00'; + assert.equal(emptyPath.toDOMElement().getAttribute('fill'), '#ffaa00'); + emptyPath.stroke = '#0000ff'; + assert.equal(emptyPath.toDOMElement().getAttribute('stroke'), '#0000ff'); + assert.equal(emptyPath.toDOMElement().getAttribute('stroke-width'), '1'); + emptyPath.strokeWidth = 2; + assert.equal(emptyPath.toDOMElement().getAttribute('stroke-width'), '2'); + emptyPath.fill = null; + assert.equal(emptyPath.toDOMElement().getAttribute('fill'), 'none'); + emptyPath.fill = 'black'; + assert.equal(emptyPath.toDOMElement().getAttribute('fill'), undefined); + }); + + after(() => { + delete global.document; + }); });