diff --git a/src/auction.js b/src/auction.js index 5722bcc6990..3c727bf1003 100644 --- a/src/auction.js +++ b/src/auction.js @@ -133,10 +133,10 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels}) try { _auctionStatus = AUCTION_COMPLETED; const adUnitCodes = _adUnitCodes; - const bids = [_bidsReceived + const bids = _bidsReceived .filter(adUnitsFilter.bind(this, adUnitCodes)) - .reduce(groupByPlacement, {})]; - _callback.apply($$PREBID_GLOBAL$$, bids); + .reduce(groupByPlacement, {}); + _callback.apply($$PREBID_GLOBAL$$, [bids, timedOut]); } catch (e) { utils.logError('Error executing bidsBackHandler', null, e); } finally { diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 3156ea671f7..3d403a34ff2 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -1091,6 +1091,7 @@ describe('Unit: Prebid Module', function () { let xhr; let adUnits; let clock; + let bidsBackHandlerStub = sinon.stub(); const BIDDER_CODE = 'sampleBidder'; let bids = [{ @@ -1140,7 +1141,12 @@ describe('Unit: Prebid Module', function () { ] }]; let adUnitCodes = ['adUnit-code']; - let auction = auctionModule.newAuction({adUnits, adUnitCodes, callback: function() {}, cbTimeout: 2000}); + let auction = auctionModule.newAuction({ + adUnits, + adUnitCodes, + callback: bidsBackHandlerStub, + cbTimeout: 2000 + }); let createAuctionStub = sinon.stub(auctionModule, 'newAuction'); createAuctionStub.returns(auction); }); @@ -1169,7 +1175,7 @@ describe('Unit: Prebid Module', function () { clock = sinon.useFakeTimers(); let requestObj = { - bidsBackHandler: function bidsBackHandlerCallback() {}, + bidsBackHandler: null, // does not need to be defined because of newAuction mock in beforeEach timeout: 2000, adUnits: adUnits }; @@ -1181,6 +1187,9 @@ describe('Unit: Prebid Module', function () { clock.tick(1); assert.ok(logMessageSpy.calledWith(sinon.match(re)), 'executeCallback called'); + + expect(bidsBackHandlerStub.getCall(0).args[1]).to.equal(true, + 'bidsBackHandler should be called with timedOut=true'); }); })