我正在尝试基于一些数据跟踪自定义事件,为此,我在监视我的自定义事件,并期望该事件得到触发。这里我试图重设我的spyevent我得到的是未定义的错误
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);
});
在上述情况下,App.ColorSelector.init();
该函数自动调用/应该获得调用fisr并触发自定义事件,并且App.ColorSelector.selectVariant($colorSelector, 'wms_III_black');
此函数依赖于init()函数
因此,我想在调用selectVariant
函数之前重置间谍。
答案 0 :(得分:0)
对于spyOnEvent
而不是calls.reset()
,请使用spyOnEvent(document, 'customEvent').reset();
。