Skip to content
Open
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
12 changes: 12 additions & 0 deletions packages/happy-dom/src/css/declaration/CSSStyleDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4845,6 +4845,18 @@ export default class CSSStyleDeclaration {
}
}

/**
* Returns an iterator, allowing you to go through all property names contained in this object.
*
* @returns Iterator.
*/
public *[Symbol.iterator](): IterableIterator<string> {
const propertyManager = this.#getPropertyManager();
for (const key in propertyManager.properties) {
yield key;
}
}

/**
* Returns item.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,41 @@ describe('CSSStyleDeclaration', () => {
});
});

describe('[Symbol.iterator]()', () => {
it('Returns an iterator for property names.', () => {
const declaration = new CSSStyleDeclaration(PropertySymbol.illegalConstructor, window, {
element
});

element.setAttribute('style', 'color: red; font-size: 12px');

expect([...declaration]).toEqual(['color', 'font-size']);
});

it('Returns an empty iterator when no styles are set.', () => {
const declaration = new CSSStyleDeclaration(PropertySymbol.illegalConstructor, window, {
element
});

expect([...declaration]).toEqual([]);
});

it('Iterates expanded shorthand properties.', () => {
const declaration = new CSSStyleDeclaration(PropertySymbol.illegalConstructor, window, {
element
});

element.setAttribute('style', 'margin: 10px');

const keys = [...declaration];

expect(keys).toContain('margin-top');
expect(keys).toContain('margin-right');
expect(keys).toContain('margin-bottom');
expect(keys).toContain('margin-left');
});
});

describe('get border()', () => {
it('Returns style property.', () => {
const declaration = new CSSStyleDeclaration(PropertySymbol.illegalConstructor, window, {
Expand Down
Loading