@@ -12,14 +12,8 @@ describe('k5a_meta_conversion', () => {
1212 // Save original utag if it exists
1313 originalUtag = window . utag ;
1414
15- // Mock utag
16- window . utag = {
17- data : { } ,
18- cfg : {
19- utDebug : true
20- } ,
21- DB : jest . fn ( )
22- } ;
15+ // Mock console.error (since we removed utag.DB)
16+ jest . spyOn ( console , 'error' ) . mockImplementation ( ) ;
2317
2418 // Clean up global variables
2519 delete global . a ;
@@ -36,6 +30,7 @@ describe('k5a_meta_conversion', () => {
3630 }
3731 delete global . a ;
3832 delete global . b ;
33+ jest . restoreAllMocks ( ) ;
3934 jest . resetModules ( ) ;
4035 } ) ;
4136
@@ -53,7 +48,6 @@ describe('k5a_meta_conversion', () => {
5348 expect ( window . k5aMeta . conversion ) . toBe ( 1 ) ;
5449 expect ( Array . isArray ( window . k5aMeta . cntTag ) ) . toBe ( true ) ;
5550 expect ( window . k5aMeta . cntTag ) . toContain ( 'offer_12345' ) ;
56- expect ( window . utag . DB ) . toHaveBeenCalledWith ( 'k5aMeta conversion set for checkout success' ) ;
5751 } ) ;
5852
5953 it ( 'should not set conversion if event_name is not "checkout"' , ( ) => {
@@ -67,7 +61,6 @@ describe('k5a_meta_conversion', () => {
6761 require ( '../../extensions/kilkaya/k5a_meta_conversion.js' ) ;
6862
6963 expect ( window . k5aMeta ) . toBeUndefined ( ) ;
70- expect ( window . utag . DB ) . not . toHaveBeenCalledWith ( 'k5aMeta conversion set for checkout success' ) ;
7164 } ) ;
7265
7366 it ( 'should not set conversion if event_action is not "success"' , ( ) => {
@@ -81,7 +74,6 @@ describe('k5a_meta_conversion', () => {
8174 require ( '../../extensions/kilkaya/k5a_meta_conversion.js' ) ;
8275
8376 expect ( window . k5aMeta ) . toBeUndefined ( ) ;
84- expect ( window . utag . DB ) . not . toHaveBeenCalledWith ( 'k5aMeta conversion set for checkout success' ) ;
8577 } ) ;
8678
8779 it ( 'should initialize k5aMeta object if it does not exist' , ( ) => {
@@ -235,13 +227,16 @@ describe('k5a_meta_conversion', () => {
235227
236228 require ( '../../extensions/kilkaya/k5a_meta_conversion.js' ) ;
237229
238- expect ( window . utag . DB ) . toHaveBeenCalledWith ( expect . stringContaining ( 'k5aMeta conversion error:' ) ) ;
230+ expect ( console . error ) . toHaveBeenCalledWith (
231+ expect . stringContaining ( '[K5A CONVERSION] Error:' ) ,
232+ expect . any ( Error )
233+ ) ;
239234
240235 // Clean up the read-only property
241236 delete window . k5aMeta ;
242237 } ) ;
243238
244- it ( 'should handle missing utag gracefully ' , ( ) => {
239+ it ( 'should work without utag dependency ' , ( ) => {
245240 global . a = 'some_value' ;
246241 global . b = {
247242 event_name : 'checkout' ,
@@ -250,9 +245,8 @@ describe('k5a_meta_conversion', () => {
250245 } ;
251246
252247 delete window . utag ;
253- global . utag = undefined ;
254248
255- // With the guard in place, the code should not throw even if utag is missing
249+ // Should work fine without utag
256250 expect ( ( ) => {
257251 require ( '../../extensions/kilkaya/k5a_meta_conversion.js' ) ;
258252 } ) . not . toThrow ( ) ;
@@ -262,25 +256,6 @@ describe('k5a_meta_conversion', () => {
262256 expect ( window . k5aMeta . conversion ) . toBe ( 1 ) ;
263257 expect ( window . k5aMeta . cntTag ) . toContain ( 'offer_12345' ) ;
264258 } ) ;
265- it ( 'should work when utag is defined but utag.data is missing' , ( ) => {
266- global . a = 'some_value' ;
267- global . b = {
268- event_name : 'checkout' ,
269- event_action : 'success' ,
270- offer_id : '12345'
271- } ;
272-
273- window . utag = {
274- DB : jest . fn ( )
275- } ;
276- // utag.data is undefined
277-
278- require ( '../../extensions/kilkaya/k5a_meta_conversion.js' ) ;
279-
280- expect ( window . k5aMeta ) . toBeDefined ( ) ;
281- expect ( window . k5aMeta . conversion ) . toBe ( 1 ) ;
282- expect ( window . k5aMeta . cntTag ) . toContain ( 'offer_12345' ) ;
283- } ) ;
284259
285260 it ( 'should handle event_name and event_action type coercion' , ( ) => {
286261 global . a = 'some_value' ;
@@ -323,44 +298,4 @@ describe('k5a_meta_conversion', () => {
323298 expect ( window . k5aMeta . cntTag ) . toContain ( 'offer_special-offer_123@test' ) ;
324299 } ) ;
325300
326- it ( 'should not log when debug mode is disabled' , ( ) => {
327- global . a = 'some_value' ;
328- global . b = {
329- event_name : 'checkout' ,
330- event_action : 'success' ,
331- offer_id : '12345'
332- } ;
333-
334- window . utag . cfg . utDebug = false ;
335-
336- require ( '../../extensions/kilkaya/k5a_meta_conversion.js' ) ;
337-
338- expect ( window . k5aMeta . conversion ) . toBe ( 1 ) ;
339- expect ( window . utag . DB ) . not . toHaveBeenCalled ( ) ;
340- } ) ;
341-
342- it ( 'should not log errors when debug mode is disabled' , ( ) => {
343- global . a = 'some_value' ;
344- global . b = {
345- event_name : 'checkout' ,
346- event_action : 'success' ,
347- offer_id : '12345'
348- } ;
349-
350- window . utag . cfg . utDebug = false ;
351-
352- // Force an error
353- Object . defineProperty ( window , 'k5aMeta' , {
354- value : null ,
355- writable : false ,
356- configurable : true
357- } ) ;
358-
359- require ( '../../extensions/kilkaya/k5a_meta_conversion.js' ) ;
360-
361- expect ( window . utag . DB ) . not . toHaveBeenCalled ( ) ;
362-
363- // Clean up
364- delete window . k5aMeta ;
365- } ) ;
366301} ) ;
0 commit comments