Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Incremental deletion of slots #6

Open
oskarleonard opened this issue Jun 9, 2017 · 0 comments
Open

Incremental deletion of slots #6

oskarleonard opened this issue Jun 9, 2017 · 0 comments

Comments

@oskarleonard
Copy link

When incrementally destroying slots, the mock GPT slots array is not altered but with the real GPT the array is altered by every slot destruction.

Example:

export function destroySlots(idsToDestroy, slots, googletag) {
    idsToDestroy = idsToDestroy || [];
    slots = slots || [];

    for (let i = 0;  i < slots.length; i++) {
        const id = slots[i].getSlotElementId();
        const shouldDeleteSlot = idsToDestroy.find((element) => {
            return id.includes(element);
        });
        console.log('HERE this lib differs from real: Slot.length ', slots.length);
        if (shouldDeleteSlot) {
            googletag.destroySlots && googletag.destroySlots([slots[i]]);
        }
    }
}
        let googletag = null;

        beforeEach(() => {
            googletag = new GPT();
            googletag.cmd.push(function() {
                googletag.defineSlot('/not/impor', [728, 90], 'SIDE-Left-Content-1').addService(googletag.pubads());
                googletag.defineSlot('/not/impor', [728, 90], 'IC-Inlist-Leaderboard').addService(googletag.pubads());
                googletag.defineSlot('/not/impor', [728, 90], 'AF-Top-Leaderboard').addService(googletag.pubads());
                googletag.defineSlot('/not/impor', [728, 90], 'SIDE-right-Content').addService(googletag.pubads());
                googletag.defineSlot('/not/impor', [728, 90], 'IC-Inlist-Leaderboard').addService(googletag.pubads());
                googletag.defineSlot('/not/impor', [728, 90], 'SIDE-right-Content-2').addService(googletag.pubads());
            });
            googletag._loaded();
        });

        test('Destroy all slots', () => {
            const idsToDestroy = ['IC-Inlist-Leaderboard', 'AF-Top-Leaderboard',
                'SIDE-Left-Content-1', 'SIDE-right-Content-2', 'SIDE-right-Content'];

            let expected = new GPT();
            expected.cmd.push(function() {

            });
            expected._loaded();

            destroySlots(idsToDestroy, googletag.pubads().getSlots(), googletag);

            expect(convertToIdArray(expected)).toEqual(convertToIdArray(googletag));
        });

Now view console logs in chrome console and in test console, they differ.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant