-
Notifications
You must be signed in to change notification settings - Fork 2
/
dom.test.ts
40 lines (36 loc) · 1.24 KB
/
dom.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { createButton } from './dom'
import { retryFailedTests } from '@fpjs-incubator/broyster/browser'
import * as UAParser from 'ua-parser-js'
retryFailedTests(3, 100)
describe('DOM', () => {
describe('createButton', () => {
it('creates a button', () => {
const button = createButton('Click me!')
expect(button).toBeInstanceOf(HTMLButtonElement)
expect(button.textContent).toBe('Click me!')
})
it('attaches ad onClick handler', () => {
const onClick = jasmine.createSpy()
const button = createButton('Click me!', onClick)
button.click()
expect(onClick).toHaveBeenCalledTimes(1)
})
it('has a secure context', () => {
const parser = new UAParser()
const result = parser.getResult()
if (!isDesktopSafari15OrHigher(result)) {
const isSecureContext = window.isSecureContext
if (isSecureContext !== undefined) {
expect(isSecureContext).toBeTrue()
}
}
function isDesktopSafari15OrHigher(result: UAParser.IResult): boolean {
return (
(result.browser.name?.startsWith('Safari') ?? false) &&
result.os.name === 'Mac OS' &&
parseInt(result.browser.version ?? '0') >= 15
)
}
})
})
})