Skip to content

Commit

Permalink
Merge pull request #497 from fatihcure-jf/task/496-domtokenlist-tostr…
Browse files Browse the repository at this point in the history
…ing-method

#496@minor: Add toString method to DOMTokenList.
  • Loading branch information
capricorn86 committed Jun 8, 2022
2 parents 31368b7 + 2ab650e commit 6be545e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/happy-dom/src/dom-token-list/DOMTokenList.ts
Expand Up @@ -212,4 +212,11 @@ export default class DOMTokenList implements IDOMTokenList {

(<number>this.length) = list.length;
}

/**
* Returns DOMTokenList value.
*/
public toString(): string {
return this.value || '';
}
}
1 change: 1 addition & 0 deletions packages/happy-dom/src/dom-token-list/IDOMTokenList.ts
Expand Up @@ -16,4 +16,5 @@ export default interface IDOMTokenList {
entries(): IterableIterator<[number, string]>;
forEach(callback: (currentValue, currentIndex, listObj) => void, thisArg?: this): void;
keys(): IterableIterator<number>;
toString(): string;
}
7 changes: 7 additions & 0 deletions packages/happy-dom/test/dom-token-list/DOMTokenList.test.ts
Expand Up @@ -203,4 +203,11 @@ describe('DOMTokenList', () => {
expect(Array.from(classList.keys())).toEqual([0, 1, 2]);
});
});

describe('toString()', () => {
it('Returns list value as string', () => {
element.className = 'class1 class2 class3';
expect(element.classList.toString()).toEqual('class1 class2 class3');
});
});
});

0 comments on commit 6be545e

Please sign in to comment.