-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'latest' into WSTEAMA-1421-create-jumpto-skeleton-component
- Loading branch information
Showing
4 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/app/components/ATIAnalytics/canonical/sendBeaconLite.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable no-eval */ | ||
import sendBeaconLite from './sendBeaconLite'; | ||
|
||
let XMLHttpRequestSpy: jest.SpyInstance<XMLHttpRequest | undefined, []>; | ||
|
||
describe('sendBeaconLite', () => { | ||
const XMLHttpRequestMock: Partial<XMLHttpRequest> = { | ||
open: jest.fn(), | ||
withCredentials: false, | ||
send: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
XMLHttpRequestSpy = jest.spyOn(window, 'XMLHttpRequest'); | ||
}); | ||
|
||
afterEach(() => { | ||
XMLHttpRequestSpy.mockRestore(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should send beacon with XHR', () => { | ||
XMLHttpRequestSpy.mockImplementation( | ||
() => XMLHttpRequestMock as XMLHttpRequest, | ||
); | ||
|
||
eval(sendBeaconLite('https://foobar.com')); | ||
|
||
expect(XMLHttpRequestMock.open).toHaveBeenCalledWith( | ||
'GET', | ||
'https://foobar.com', | ||
true, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const sendBeaconLite = (atiPageViewUrlString: string) => ` | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "${atiPageViewUrlString}", true); | ||
xhr.withCredentials = true; | ||
xhr.send(); | ||
`; | ||
|
||
export default sendBeaconLite; |