Skip to content

Commit

Permalink
chore: [#1364] Adds unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
capricorn86 committed Mar 27, 2024
1 parent 1ad442b commit c0e1b48
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/happy-dom/test/window/BrowserWindow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,42 @@ describe('BrowserWindow', () => {
expect(computedStyle.color).toBe('green');
});

it('Handles variables in style attributes.', () => {
const div = document.createElement('div');
div.setAttribute('style', '--my-color1: pink;');

const style = document.createElement('style');

style.textContent = `
div {
border-color: var(--my-color1);
}
`;

document.head.appendChild(style);
document.body.appendChild(div);

expect(window.getComputedStyle(div).getPropertyValue('border-color')).toBe('pink');
});

it('Handles variables in root of style.', () => {
const div = document.createElement('div');
const style = document.createElement('style');

style.textContent = `
div {
border-color: var(--my-color1);
}
--my-color1: pink;
`;

document.head.appendChild(style);
document.body.appendChild(div);

expect(window.getComputedStyle(div).getPropertyValue('border-color')).toBe('pink');
});

it('Ingores invalid selectors in parsed CSS.', () => {
const parent = document.createElement('div');
const element = document.createElement('span');
Expand Down

0 comments on commit c0e1b48

Please sign in to comment.