File tree Expand file tree Collapse file tree 4 files changed +51
-1
lines changed
Expand file tree Collapse file tree 4 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 11type QueueItem = {
2- method : 'track' | 'set' | 'ecommerce' ;
2+ method : 'track' | 'set' | 'ecommerce' | 'spaPageview' ;
33 arguments : unknown ;
44} ;
55
@@ -29,6 +29,9 @@ export function getZaraz() {
2929 ecommerce : ( ...args : unknown [ ] ) => {
3030 queue . push ( { method : 'ecommerce' , arguments : args } ) ;
3131 } ,
32+ spaPageview : ( ...args : unknown [ ] ) => {
33+ queue . push ( { method : 'spaPageview' , arguments : args } ) ;
34+ } ,
3235 } ;
3336 }
3437
Original file line number Diff line number Diff line change 22
33import { ecommerce } from './ecommerce' ;
44import { set } from './set' ;
5+ import { spaPageview } from './spa-pageview' ;
56import { track } from './track' ;
67
78declare global {
@@ -15,9 +16,11 @@ export const zaraz = {
1516 track,
1617 set,
1718 ecommerce,
19+ spaPageview,
1820} ;
1921
2022// Export typing etc.
2123export * from './ecommerce' ;
2224export * from './set' ;
2325export * from './track' ;
26+ export * from './spa-pageview' ;
Original file line number Diff line number Diff line change 1+ import { spaPageview } from './spa-pageview' ;
2+
3+ const trackMock = jest . fn ( ) ;
4+ const setMock = jest . fn ( ) ;
5+ const ecommerceMock = jest . fn ( ) ;
6+ const spaPageviewMock = jest . fn ( ) ;
7+
8+ declare global {
9+ interface Window {
10+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11+ zaraz : any ;
12+ }
13+ }
14+
15+ let windowObj : Window & typeof globalThis ;
16+
17+ beforeAll ( ( ) => {
18+ windowObj = window ;
19+ } ) ;
20+
21+ afterAll ( ( ) => {
22+ window = windowObj ;
23+ } ) ;
24+
25+ describe ( 'set()' , ( ) => {
26+ it ( 'should call zaraz spaPageview when called' , ( ) => {
27+ window . zaraz = {
28+ track : trackMock ,
29+ set : setMock ,
30+ ecommerce : ecommerceMock ,
31+ spaPageview : spaPageviewMock ,
32+ } ;
33+
34+ spaPageview ( ) ;
35+
36+ expect ( spaPageviewMock ) . toHaveBeenCalledWith ( ) ;
37+ } ) ;
38+ } ) ;
Original file line number Diff line number Diff line change 1+ import { getZaraz } from './helpers/get-zaraz' ;
2+
3+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4+ export function spaPageview ( ) : void {
5+ getZaraz ( ) . spaPageview ( ) ;
6+ }
You can’t perform that action at this time.
0 commit comments