Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [#1342] Make DOMTokenList iterable #1365

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/happy-dom/src/dom-token-list/DOMTokenList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export default class DOMTokenList {
return this.#ownerElement.getAttribute(this.#attributeName);
}

/**
* Returns an iterator, allowing you to go through all values of the key/value pairs contained in this object.
*/
public [Symbol.iterator](): IterableIterator<string> {
return this.#getTokenList().values();
}

/**
* Get ClassName.
*
Expand Down
9 changes: 9 additions & 0 deletions packages/happy-dom/test/dom-token-list/DOMTokenList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,19 @@ describe('DOMTokenList', () => {
describe('values()', () => {
it('A stringifier property that returns the value of the list as a string.', () => {
element.className = 'class1 class2 class3';
expect(typeof classList.values()[Symbol.iterator]).toEqual('function');
expect(Array.from(classList.values())).toEqual(['class1', 'class2', 'class3']);
});
});

describe('Iterator', () => {
it('A stringifier property that returns the value of the list as a string.', () => {
element.className = 'class1 class2 class3';
expect(typeof classList[Symbol.iterator]).toEqual('function');
expect(Array.from(classList)).toEqual(['class1', 'class2', 'class3']);
});
});

describe('entries()', () => {
it('Returns an iterator, allowing you to go through all key/value pairs contained in this object.', () => {
element.className = 'class1 class2 class3';
Expand Down
Loading