added a simple test (#4647)

This commit is contained in:
Andrea Bogazzi 2018-01-26 11:12:27 +01:00 committed by GitHub
parent 43ebcd8278
commit 4f446020ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View file

@ -1429,7 +1429,11 @@
el.width = boundingRect.width;
el.height = boundingRect.height;
fabric.util.wrapElement(el, 'div');
var canvas = new fabric.StaticCanvas(el, { enableRetinaScaling: options.enableRetinaScaling });
var canvas = new fabric.StaticCanvas(el, {
enableRetinaScaling: options.enableRetinaScaling,
renderOnAddRemove: false,
skipOffscreen: false,
});
// to avoid common confusion https://github.com/kangax/fabric.js/issues/806
if (options.format === 'jpg') {
options.format = 'jpeg';
@ -1449,10 +1453,12 @@
var originalCanvas = this.canvas;
canvas.add(this);
var data = canvas.toDataURL(options);
this.set(origParams).setCoords();
this.canvas = originalCanvas;
// canvas.dispose will call image.dispose that will nullify the elements
// since this canvas is a simple element for the process, we remove references
// to objects in this way in order to avoid object trashing.
canvas._objects = [];
canvas.dispose();
canvas = null;

View file

@ -567,4 +567,16 @@
done();
});
});
QUnit.test('consecutive dataURLs give same result.', function(assert) {
var done = assert.async();
createImageObject(function(image) {
var data1 = image.toDataURL();
var data2 = image.toDataURL();
var data3 = image.toDataURL();
assert.equal(data1, data2, 'dataurl does not change 1');
assert.equal(data1, data3, 'dataurl does not change 2');
done();
});
});
})();