From 4c58078809ce41aa08d8a0079d856c67ba911b96 Mon Sep 17 00:00:00 2001 From: Krystian Jarmicki Date: Mon, 24 Nov 2014 13:37:52 +0100 Subject: [PATCH] issue#9 --- lib/iframe.js | 8 ++++++-- test/iframe.test.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/iframe.js b/lib/iframe.js index d3f11ec..e2ab5a0 100644 --- a/lib/iframe.js +++ b/lib/iframe.js @@ -42,8 +42,12 @@ Iframe.prototype.remove = function() { Iframe.prototype.resize = function(w, h) { if (w) { this.width = w; } if (h) { this.height = h; } - this.element.style.width = validSize(this.width); - this.element.style.height = validSize(this.height); + + if (this.element && this.element.style) { + this.element.style.width = validSize(this.width); + this.element.style.height = validSize(this.height); + } + return this; }; diff --git a/test/iframe.test.js b/test/iframe.test.js index a336313..be1631c 100644 --- a/test/iframe.test.js +++ b/test/iframe.test.js @@ -91,4 +91,15 @@ describe('iframe', function () { expect(iframe.element.style.width).to.equal('250px'); expect(iframe.element.style.height).to.equal('200px'); }); + + it('should not throw an error when resizing if element was removed', function() { + var iframe = new Iframe('resize-test', {width:100, height:100, iframeUrl:'about:blank'}); + var fakeParent = document.createElement('div'); + + iframe.makeIframe(); + fakeParent.appendChild(iframe.wrapper); + iframe.remove(); + expect(iframe.resize).to.not.throw(Error); + }); + });