/
githubmirror
/
amphtml
Обзор
Документация
Войти
/
githubmirror
/
amphtml
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
test/unit/utils/test-analytics.js
62 строки
2 KB
Ryan Cebulko
♻️ Move files into #core, #utils to enable tsc typechecking (#36277)
07 окт 2021, 23:26
Не верифицирован
07 окт 2021, 23:26
b6d1550
Код
Авторство
О чём код?
import {Services} from '#service'; import {triggerAnalyticsEvent} from '#utils/analytics'; import { getServiceForDoc, registerServiceBuilderForDoc, resetServiceForTesting, } from '../../../src/service-helpers'; describes.realWin( 'analytics', { amp: true, }, (env) => { let timer; let ampdoc; describe('triggerAnalyticsEvent', () => { let triggerEventSpy; class MockInstrumentation { triggerEventForTarget(nodeOrDoc, eventType, opt_vars) { triggerEventSpy(nodeOrDoc, eventType, opt_vars); } } beforeEach(() => { timer = Services.timerFor(env.win); ampdoc = env.ampdoc; triggerEventSpy = env.sandbox.spy(); resetServiceForTesting(window, 'amp-analytics-instrumentation'); }); it('should not do anything if analytics is not installed', () => { triggerAnalyticsEvent(ampdoc.win.document, 'hello'); return timer.promise(50).then(() => { expect(triggerEventSpy).to.have.not.been.called; }); }); it('should trigger analytics event if analytics is installed', () => { registerServiceBuilderForDoc( ampdoc, 'amp-analytics-instrumentation', MockInstrumentation ); // Force instantiation getServiceForDoc(ampdoc, 'amp-analytics-instrumentation'); triggerAnalyticsEvent(ampdoc.win.document, 'hello'); return timer.promise(50).then(() => { expect(triggerEventSpy).to.have.been.called; expect(triggerEventSpy).to.have.been.calledWith( ampdoc.win.document, 'hello' ); }); }); }); } );