Reset spyOnEvent on document

84 Views Asked by At

I'm trying to track a custom event based on some data, for this I'm spying on my custom event and expecting the event to get trigger or not. Here am trying to reset my spyevent all I get is undefined error

TypeError: undefined is not an object (evaluating 'spyOnEvent(document, 'product.trackVariantChanged').calls.reset')

it('selects a variant without triggering the product.trackVariantChanged event on document', function() {
            spyOnEvent(document, 'variantChanged');
            spyOnEvent(document, 'product.trackVariantChanged').calls.reset();
            App.ColorSelector.init(); // this function automatically calls custom triggers when it calls

            App.ColorSelector.selectVariant($colorSelector, 'wms_III_black'); //this function has a depedency on init()

            expect('variantChanged').toHaveBeenTriggeredOn(document);
        expect('product.trackVariantChanged').not.toHaveBeenTriggeredOn(document);  

            App.ColorSelector.selectVariant($colorSelector, 'wms_III_white');

            expect('variantChanged').toHaveBeenTriggeredOn(document);
        expect('product.trackVariantChanged').not.toHaveBeenTriggeredOn(document);  
        });

from above case App.ColorSelector.init(); this function automatically calls/ should get call fisr and triggers custom event and App.ColorSelector.selectVariant($colorSelector, 'wms_III_black'); this function has a dependency on init() function
So I want to reset the spy before the selectVariant function get called.

1

There are 1 best solutions below

0
Vivek Vikranth On

For spyOnEvent instead of calls.reset() use spyOnEvent(document, 'customEvent').reset(); it will work.