diff --git a/libraries/browser-tracker-core/test/out_queue.test.ts b/libraries/browser-tracker-core/test/out_queue.test.ts index b5e8668f9..e3088b06c 100644 --- a/libraries/browser-tracker-core/test/out_queue.test.ts +++ b/libraries/browser-tracker-core/test/out_queue.test.ts @@ -40,21 +40,20 @@ const readPostQueue = () => { describe('OutQueueManager', () => { const maxQueueSize = 2; - var xhrMock: XMLHttpRequest; + var xhrMock: Partial; var xhrOpenMock: jest.Mock; beforeEach(() => { localStorage.clear(); xhrOpenMock = jest.fn(); xhrMock = { - ...new XMLHttpRequest(), open: xhrOpenMock, send: jest.fn(), setRequestHeader: jest.fn(), withCredentials: true, }; - jest.spyOn(window, 'XMLHttpRequest').mockImplementation(() => xhrMock); + jest.spyOn(window, 'XMLHttpRequest').mockImplementation(() => xhrMock as XMLHttpRequest); }); const respondMockRequest = (status: number) => { @@ -371,7 +370,7 @@ describe('OutQueueManager', () => { let retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(1); - xhrMock.onabort?.(new ProgressEvent('abort')); + (xhrMock as XMLHttpRequest).ontimeout?.(new ProgressEvent('abort')); retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(1); @@ -384,7 +383,7 @@ describe('OutQueueManager', () => { let retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(1); - xhrMock.ontimeout?.(new ProgressEvent('timeout')); + (xhrMock as XMLHttpRequest).ontimeout?.(new ProgressEvent('timeout')); retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(1); @@ -397,7 +396,7 @@ describe('OutQueueManager', () => { let retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(1); - xhrMock.onerror?.(new ProgressEvent('error')); + (xhrMock as XMLHttpRequest).onerror?.(new ProgressEvent('error')); retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(1); @@ -435,7 +434,7 @@ describe('OutQueueManager', () => { let retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(1); - xhrMock.onabort?.(new ProgressEvent('abort')); + (xhrMock as XMLHttpRequest).ontimeout?.(new ProgressEvent('abort')); retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(0); @@ -448,7 +447,7 @@ describe('OutQueueManager', () => { let retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(1); - xhrMock.ontimeout?.(new ProgressEvent('timeout')); + (xhrMock as XMLHttpRequest).ontimeout?.(new ProgressEvent('timeout')); retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(0); @@ -461,7 +460,7 @@ describe('OutQueueManager', () => { let retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(1); - xhrMock.onerror?.(new ProgressEvent('error')); + (xhrMock as XMLHttpRequest).onerror?.(new ProgressEvent('error')); retrievedQueue = readPostQueue(); expect(retrievedQueue).toHaveLength(0);