Skip to content

Commit

Permalink
Additional test case
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-orlik committed Jul 4, 2024
1 parent f67a3ff commit 1d1a226
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,37 @@ if (!global.crypto) {
}

describe('custom-html', () => {
it('executes html injection', () => {
it('executes simple html injection', () => {
const executedJS: string[] = []
const fakeEvent = new Event('pageview', {}) as MCEvent
fakeEvent.payload = {
htmlCode: `<p>some text</p>
<script>console.log('Log from MC')</script>
<script>console.log('Log 2 from MC')</script>`,
}
fakeEvent.client = {
emitter: 'browser',
userAgent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
language: 'en-US',
referer: '',
ip: '127.0.0.1',
url: new URL('http://127.0.0.1:1337'),
execute: jsString => {
executedJS.push(jsString)
return true
},
}
handler(fakeEvent)
expect(executedJS).toHaveLength(3)
expect(executedJS[0]).toEqual(
"const d = document.createElement('div');d.innerHTML = `<p>some text</p>`;document.body.appendChild(d);"
)
expect(executedJS[1]).toEqual(`console.log('Log from MC')`)
expect(executedJS[2]).toEqual(`console.log('Log 2 from MC')`)
})

it('executes html injection with scripts that wait for other scripts', () => {
const executedJS: string[] = []
const fakeEvent = new Event('pageview', {}) as MCEvent
fakeEvent.payload = {
Expand Down

0 comments on commit 1d1a226

Please sign in to comment.