diff --git a/src/dom_components/model/ComponentImage.js b/src/dom_components/model/ComponentImage.js index 19e2e39a4..0c0c23688 100644 --- a/src/dom_components/model/ComponentImage.js +++ b/src/dom_components/model/ComponentImage.js @@ -95,6 +95,21 @@ export default Component.extend( return this.get('src') === result(this, 'defaults').src; }, + /** + * Return a shallow copy of the model's attributes for JSON + * stringification. + * @return {Object} + * @private + */ + toJSON(...args) { + const obj = Component.prototype.toJSON.apply(this, args); + if (obj.src === obj.attributes.src) { + delete obj.src; + } + + return obj; + }, + /** * Parse uri * @param {string} uri diff --git a/test/specs/dom_components/model/ComponentImage.js b/test/specs/dom_components/model/ComponentImage.js index 177dc305d..d8ddb885f 100644 --- a/test/specs/dom_components/model/ComponentImage.js +++ b/test/specs/dom_components/model/ComponentImage.js @@ -8,6 +8,10 @@ describe('ComponentImage', () => { componentImage = new ComponentImage(); }); + test('`src` property is defined after initializing', () => { + expect(componentImage.get('src')).toBeDefined(); + }); + describe('.getAttrToHTML', () => { let getSrcResultSpy; const fakeAttributes = {};