Skip to content

Commit 98319e2

Browse files
committed
chore(tests): extend DOM globals and reorder test blocks A–Z 🍨
- Add DocumentFragment, HTMLIFrameElement, HTMLLabelElement, HTMLTemplateElement in DOM.ts - Reorder test blocks in Constant.test, Helper.test, and Validator.test A–Z
1 parent e30593d commit 98319e2

File tree

4 files changed

+50
-46
lines changed

4 files changed

+50
-46
lines changed

tests/Constant.test.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ Deno.test('Constant.containerTags does not include void tags', () => {
5151
}
5252
})
5353

54+
Deno.test('Constant.containerTags includes meter audio video hgroup and inline tags', () => {
55+
const expectedInlineTags = [
56+
'abbr',
57+
'audio',
58+
'cite',
59+
'code',
60+
'del',
61+
'em',
62+
'hgroup',
63+
'ins',
64+
'mark',
65+
'meter',
66+
'q',
67+
'strong',
68+
'time',
69+
'video'
70+
]
71+
for (const tag of expectedInlineTags) {
72+
assertEquals(Constant.containerTags.includes(tag), true)
73+
}
74+
})
75+
5476
Deno.test('Constant.containerTags includes new form table semantic tags', () => {
5577
const expectedSemanticTags = [
5678
'address',
@@ -78,28 +100,6 @@ Deno.test('Constant.containerTags includes new form table semantic tags', () =>
78100
}
79101
})
80102

81-
Deno.test('Constant.containerTags includes meter audio video hgroup and inline tags', () => {
82-
const expectedInlineTags = [
83-
'abbr',
84-
'audio',
85-
'cite',
86-
'code',
87-
'del',
88-
'em',
89-
'hgroup',
90-
'ins',
91-
'mark',
92-
'meter',
93-
'q',
94-
'strong',
95-
'time',
96-
'video'
97-
]
98-
for (const tag of expectedInlineTags) {
99-
assertEquals(Constant.containerTags.includes(tag), true)
100-
}
101-
})
102-
103103
Deno.test('Constant.svgNamespace is SVG namespace string', () => {
104104
assertEquals(Constant.svgNamespace, 'http://www.w3.org/2000/svg')
105105
})

tests/DOM.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { parseHTML } from 'linkedom'
22

33
const { window } = parseHTML('<!DOCTYPE html><html><body></body></html>')
44
const globalScope = globalThis as Record<string, unknown>
5+
globalScope['DocumentFragment'] = window.DocumentFragment ?? class DocumentFragment {}
56
globalScope['HTMLElement'] = window.HTMLElement
67
globalScope['Element'] = window.Element
78
globalScope['HTMLInputElement'] = window.HTMLInputElement
@@ -13,7 +14,10 @@ globalScope['HTMLImageElement'] = window.HTMLImageElement
1314
globalScope['HTMLAnchorElement'] = window.HTMLAnchorElement
1415
globalScope['HTMLDetailsElement'] = window.HTMLDetailsElement
1516
globalScope['HTMLDialogElement'] = window.HTMLDialogElement
17+
globalScope['HTMLIFrameElement'] = window.HTMLIFrameElement ?? window.HTMLElement
18+
globalScope['HTMLLabelElement'] = window.HTMLLabelElement ?? window.HTMLElement
1619
globalScope['HTMLOptGroupElement'] = window.HTMLOptGroupElement
20+
globalScope['HTMLTemplateElement'] = window.HTMLTemplateElement ?? window.HTMLElement
1721
globalScope['HTMLOptionElement'] = window.HTMLOptionElement
1822

1923
export const document = window.document

tests/Helper.test.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ Deno.test('el.dialog exists and returns node with type dialog', () => {
6868
assertEquals(node.content, 'Close')
6969
})
7070

71-
Deno.test('el.dl el.dt el.dd exist', () => {
72-
const node = el.dl(el.dt('Term'), el.dd('Definition'))
73-
assertEquals(node.type, 'dl')
74-
assertEquals(node.children?.length, 2)
75-
assertEquals(node.children?.[0]?.type, 'dt')
76-
assertEquals(node.children?.[1]?.type, 'dd')
77-
})
78-
7971
Deno.test('el.div with children returns children array', () => {
8072
const node = el.div(el.span('a'), el.span('b'))
8173
assertEquals(node.type, 'div')
@@ -123,6 +115,14 @@ Deno.test('el.div() returns node with type div', () => {
123115
assertEquals(node.type, 'div')
124116
})
125117

118+
Deno.test('el.dl el.dt el.dd exist', () => {
119+
const node = el.dl(el.dt('Term'), el.dd('Definition'))
120+
assertEquals(node.type, 'dl')
121+
assertEquals(node.children?.length, 2)
122+
assertEquals(node.children?.[0]?.type, 'dt')
123+
assertEquals(node.children?.[1]?.type, 'dd')
124+
})
125+
126126
Deno.test('el.fieldset exists and returns node with type fieldset', () => {
127127
const node = el.fieldset(el.legend('Label'), el.input())
128128
assertEquals(node.type, 'fieldset')
@@ -161,11 +161,6 @@ Deno.test('el.iframe exists and returns node with type iframe', () => {
161161
assertEquals(node.type, 'iframe')
162162
})
163163

164-
Deno.test('el.img with no args returns img node', () => {
165-
const node = el.img()
166-
assertEquals(node.type, 'img')
167-
})
168-
169164
Deno.test('el.img with content throws', () => {
170165
assertThrows(
171166
() => el.img('text' as unknown as Record<string, unknown>),
@@ -174,6 +169,11 @@ Deno.test('el.img with content throws', () => {
174169
)
175170
})
176171

172+
Deno.test('el.img with no args returns img node', () => {
173+
const node = el.img()
174+
assertEquals(node.type, 'img')
175+
})
176+
177177
Deno.test('el.img with props returns img with src alt', () => {
178178
const node = el.img({ src: '/x.png', alt: 'image' })
179179
assertEquals(node.type, 'img')
@@ -297,20 +297,20 @@ Deno.test('el.summary exists and returns node with type summary', () => {
297297
assertEquals(node.content, 'Summary text')
298298
})
299299

300-
Deno.test('Helper.node() static equals Helper.el.node()', () => {
301-
const resultA = Helper.node('span', 'text')
302-
const resultB = Helper.el.node('span', 'text')
303-
assertEquals(resultA.type, resultB.type)
304-
assertEquals(resultA.content, resultB.content)
305-
})
306-
307300
Deno.test('Helper.node() static equals el.node()', () => {
308301
const resultA = Helper.node('div', { id: 'x' })
309302
const resultB = el.node('div', { id: 'x' })
310303
assertEquals(resultA.type, resultB.type)
311304
assertEquals(resultA.id, resultB.id)
312305
})
313306

307+
Deno.test('Helper.node() static equals Helper.el.node()', () => {
308+
const resultA = Helper.node('span', 'text')
309+
const resultB = Helper.el.node('span', 'text')
310+
assertEquals(resultA.type, resultB.type)
311+
assertEquals(resultA.content, resultB.content)
312+
})
313+
314314
Deno.test('Helper.root() and el.root() are same', () => {
315315
const resultA = Helper.root(el.div())
316316
const resultB = el.root(el.div())

tests/Validator.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ Deno.test('Validator.isLayout returns true for number and string values', () =>
3131
assertEquals(Validator.isLayout({ width: '100%', height: 50 }), true)
3232
})
3333

34-
Deno.test('Validator.isPlainObject returns false for null', () => {
35-
assertEquals(Validator.isPlainObject(null), false)
36-
})
37-
3834
Deno.test('Validator.isPlainObject returns false for array', () => {
3935
assertEquals(Validator.isPlainObject([]), false)
4036
assertEquals(Validator.isPlainObject([1, 2]), false)
4137
})
4238

39+
Deno.test('Validator.isPlainObject returns false for null', () => {
40+
assertEquals(Validator.isPlainObject(null), false)
41+
})
42+
4343
Deno.test('Validator.isPlainObject returns false for primitive', () => {
4444
assertEquals(Validator.isPlainObject(1), false)
4545
assertEquals(Validator.isPlainObject('x'), false)

0 commit comments

Comments
 (0)