diff --git a/src/Bling.js b/src/Bling.js index de8feff..968fdcd 100644 --- a/src/Bling.js +++ b/src/Bling.js @@ -668,7 +668,7 @@ class Bling extends Component { clear() { const adSlot = this._adSlot; - if (adSlot) { + if (adSlot && adSlot.hasOwnProperty("getServices")) { // googletag.ContentService doesn't clear content const services = adSlot.getServices(); if (this._divId && services.some(s => !!s.setContent)) { diff --git a/src/createManager.js b/src/createManager.js index e3eeda9..e97abca 100644 --- a/src/createManager.js +++ b/src/createManager.js @@ -321,9 +321,12 @@ export class AdManager extends EventEmitter { if (!instance.notInViewport()) { instance.defineSlot(); const adSlot = instance.adSlot; - const services = adSlot.getServices(); - if (!hasPubAdsService) { - hasPubAdsService = services.filter(service => !!service.enableAsyncRendering).length > 0; + + if (adSlot && adSlot.hasOwnProperty("getServices")) { + const services = adSlot.getServices(); + if (!hasPubAdsService) { + hasPubAdsService = services.filter(service => !!service.enableAsyncRendering).length > 0; + } } } }); diff --git a/test/Bling.spec.js b/test/Bling.spec.js index 2c56f16..8fd61fa 100644 --- a/test/Bling.spec.js +++ b/test/Bling.spec.js @@ -216,6 +216,23 @@ describe("Bling", () => { clear.restore(); }); + it("handles empty adSlot on clear", () => { + const instance = new Bling(); + instance._adSlot = {}; + + expect(() => { + instance.clear(); + }).to.not.throw("adSlot.getServices is not a function"); + }); + + it("calls getServices on adSlot on clear", () => { + const instance = new Bling(); + const adSlot = sinon.mock({getServices: () => {}}); + adSlot.expects("getServices").once(); + instance._adSlot = adSlot; + instance.clear(); + }); + it("updates correlator", () => { const updateCorrelator = sinon.stub(Bling._adManager, "updateCorrelator");