-
Notifications
You must be signed in to change notification settings - Fork 239
/
isElementType.ts
42 lines (38 loc) 路 1.47 KB
/
isElementType.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
41
42
import {isElementType} from '#src/utils'
import {setup} from '#testHelpers/utils'
describe('check element type per namespace, tagname and props', () => {
test('check in HTML document', async () => {
const {elements} = setup(`<input readonly="true"/><textarea/>`)
expect(isElementType(elements[0], 'input')).toBe(true)
expect(isElementType(elements[0], 'input', {readOnly: false})).toBe(false)
expect(isElementType(elements[1], 'input')).toBe(false)
expect(isElementType(elements[1], ['input', 'textarea'])).toBe(true)
expect(
isElementType(elements[1], ['input', 'textarea'], {readOnly: false}),
).toBe(true)
})
test('check in XML document', async () => {
// const {element} = setup(`<input readonly="true"/>`)
const dom = new DOMParser().parseFromString(
`
<root xmlns="http://example.com/foo">
<input readonly="true"/>
<input xmlns="http://www.w3.org/1999/xhtml" readonly="true"/>
</root>
`,
'application/xml',
)
const xmlInput = dom.getElementsByTagNameNS(
'http://example.com/foo',
'input',
)[0]
const htmlInput = dom.getElementsByTagNameNS(
'http://www.w3.org/1999/xhtml',
'input',
)[0]
expect(isElementType(xmlInput, 'input')).toBe(false)
expect(isElementType(htmlInput, 'input')).toBe(true)
expect(isElementType(htmlInput, 'input', {readOnly: true})).toBe(true)
expect(isElementType(htmlInput, 'input', {readOnly: false})).toBe(false)
})
})