From 4799db0a6e725db67b7b1566d3e5f0b358d4fea4 Mon Sep 17 00:00:00 2001 From: Tomas Roos Date: Thu, 9 Jan 2020 15:45:54 +0100 Subject: [PATCH] Added customSlotMatching test for setTargetingForGPTAsync --- test/spec/unit/pbjs_api_spec.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 094220ea521..5b785e2f50a 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -869,6 +869,33 @@ describe('Unit: Prebid Module', function () { assert.deepEqual(slots[1].spySetTargeting.args, targeting, 'google tag targeting options not matching'); }); + it('should set googletag targeting keys to specific slot with customSlotMatching', function () { + // same ad unit code but two differnt divs + // we make sure we can set targeting for a specific one with customSlotMatching + + $$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: false }); + + var slots = [ + new Slot('div-id-one', config.adUnitCodes[0]), + new Slot('div-id-two', config.adUnitCodes[0]), + new Slot(config.adUnitElementIDs[2], config.adUnitCodes[2]) + ]; + + slots[0].spySetTargeting.resetHistory(); + slots[1].spySetTargeting.resetHistory(); + window.googletag.pubads().setSlots(slots); + + $$PREBID_GLOBAL$$.setTargetingForGPTAsync([config.adUnitCodes[0]], (slot) => { + return (adUnitCode) => { + return slots[0].getSlotElementId() === slot.getSlotElementId(); + }; + }); + + var expected = getTargetingKeys(); + expect(slots[0].spySetTargeting.args).to.deep.contain.members(expected); + expect(slots[1].spySetTargeting.args).to.not.deep.contain.members(expected); + }); + it('should set targeting when passed a string ad unit code with enableSendAllBids', function () { var slots = createSlotArray(); window.googletag.pubads().setSlots(slots);