Skip to content

Commit 26c3e5d

Browse files
committed
fix: [#1634] Fixes the implementation for the HTMLTableCellElement.headers property
1 parent b7f0b8f commit 26c3e5d

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

packages/happy-dom/src/nodes/html-element/HTMLElement.ts

+8-18
Original file line numberDiff line numberDiff line change
@@ -613,15 +613,10 @@ export default class HTMLElement extends Element {
613613
public override [PropertySymbol.connectedToDocument](): void {
614614
super[PropertySymbol.connectedToDocument]();
615615

616-
if (
617-
this[PropertySymbol.ownerDocument][PropertySymbol.window].document ===
618-
this[PropertySymbol.ownerDocument]
619-
) {
620-
this[PropertySymbol.window][PropertySymbol.customElementReactionStack].enqueueReaction(
621-
this,
622-
'connectedCallback'
623-
);
624-
}
616+
this[PropertySymbol.window][PropertySymbol.customElementReactionStack].enqueueReaction(
617+
this,
618+
'connectedCallback'
619+
);
625620
}
626621

627622
/**
@@ -630,15 +625,10 @@ export default class HTMLElement extends Element {
630625
public override [PropertySymbol.disconnectedFromDocument](): void {
631626
super[PropertySymbol.disconnectedFromDocument]();
632627

633-
if (
634-
this[PropertySymbol.ownerDocument][PropertySymbol.window].document ===
635-
this[PropertySymbol.ownerDocument]
636-
) {
637-
this[PropertySymbol.window][PropertySymbol.customElementReactionStack].enqueueReaction(
638-
this,
639-
'disconnectedCallback'
640-
);
641-
}
628+
this[PropertySymbol.window][PropertySymbol.customElementReactionStack].enqueueReaction(
629+
this,
630+
'disconnectedCallback'
631+
);
642632
}
643633

644634
/**

packages/happy-dom/src/nodes/html-table-cell-element/HTMLTableCellElement.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,22 @@ export default class HTMLTableCellElement extends HTMLElement {
6969
}
7070

7171
/**
72-
* A DOMTokenList describing a list of id of <th> elements that represent headers associated with the cell. It reflects the headers attribute.
72+
* Returns headers.
7373
*
74-
* @returns Headers.
74+
* @returns headers.
7575
*/
76-
public get headers(): DOMTokenList {
77-
if (!this[PropertySymbol.headers]) {
78-
this[PropertySymbol.headers] = new DOMTokenList(
79-
PropertySymbol.illegalConstructor,
80-
this,
81-
'headers'
82-
);
83-
}
84-
return <DOMTokenList>this[PropertySymbol.headers];
76+
public get headers(): string {
77+
return this.getAttribute('headers') || '';
78+
}
79+
80+
/**
81+
* Sets headers.
82+
*
83+
* @param value headers.
84+
*/
85+
public set headers(value: string) {
86+
this.setAttribute('headers', String(value));
87+
// TODO: implement metadata update if needed.
8588
}
8689

8790
/**

packages/happy-dom/test/nodes/html-table-cell-element/HTMLTableCellElement.test.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,27 @@ describe('HTMLTableCellElement', () => {
9595
});
9696

9797
describe('get headers()', () => {
98-
it('Should return a DOMTokenList describing a list of id of <th> elements', () => {
99-
expect(element.headers).instanceOf(DOMTokenList);
100-
expect(element.headers).toBe(element.headers);
98+
it('Should return an empty string by default', () => {
99+
expect(element.headers).toBe('');
100+
});
101+
102+
it('Should return the attribute value', () => {
103+
element.setAttribute('headers', 'header1 header2');
104+
expect(element.headers).toBe('header1 header2');
105+
});
106+
});
101107

102-
element.setAttribute('headers', 'id1 id2');
108+
describe('set headers()', () => {
109+
it('Should set the attribute value', () => {
110+
element.headers = 'header1 header2';
111+
expect(element.getAttribute('headers')).toBe('header1 header2');
112+
});
103113

104-
expect(element.headers.length).toBe(2);
105-
expect(element.headers[0]).toBe('id1');
106-
expect(element.headers[1]).toBe('id2');
114+
it('Should stringify the value', () => {
115+
element.headers = <string>(<unknown>1);
116+
expect(element.getAttribute('headers')).toBe('1');
117+
element.headers = <string>(<unknown>null);
118+
expect(element.getAttribute('headers')).toBe('null');
107119
});
108120
});
109121

0 commit comments

Comments
 (0)