Skip to content

Commit

Permalink
capricorn86#976@minor: Add background image test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
malko committed Jul 13, 2023
1 parent e72825e commit ca9a7ac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
10 changes: 7 additions & 3 deletions packages/happy-dom/test/css/CSSParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,26 @@ describe('CSSParser', () => {
expect((<CSSStyleRule>cssRules[1]).parentStyleSheet).toBe(cssStyleSheet);
expect((<CSSStyleRule>cssRules[1]).selectorText).toBe('.container');
expect((<CSSStyleRule>cssRules[1]).cssText).toBe(
'.container { flex-grow: 1; display: flex; flex-direction: column; overflow: hidden; --css-variable: 1px; }'
'.container { flex-grow: 1; display: flex; flex-direction: column; overflow: hidden; --css-variable: 1px; background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="), url("test.jpg"); }'
);
expect((<CSSStyleRule>cssRules[1]).style.length).toBe(5);
expect((<CSSStyleRule>cssRules[1]).style.length).toBe(6);
expect((<CSSStyleRule>cssRules[1]).style.parentRule).toBe(cssRules[1]);
expect((<CSSStyleRule>cssRules[1]).style[0]).toBe('flex-grow');
expect((<CSSStyleRule>cssRules[1]).style[1]).toBe('display');
expect((<CSSStyleRule>cssRules[1]).style[2]).toBe('flex-direction');
expect((<CSSStyleRule>cssRules[1]).style[3]).toBe('overflow');
expect((<CSSStyleRule>cssRules[1]).style[4]).toBe('--css-variable');
expect((<CSSStyleRule>cssRules[1]).style[5]).toBe('background-image');
expect((<CSSStyleRule>cssRules[1]).style.flexGrow).toBe('1');
expect((<CSSStyleRule>cssRules[1]).style.display).toBe('flex');
expect((<CSSStyleRule>cssRules[1]).style.flexDirection).toBe('column');
expect((<CSSStyleRule>cssRules[1]).style.overflow).toBe('hidden');
expect((<CSSStyleRule>cssRules[1]).style.getPropertyValue('--css-variable')).toBe('1px');
expect((<CSSStyleRule>cssRules[1]).style.backgroundImage).toBe(
'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="), url("test.jpg")'
);
expect((<CSSStyleRule>cssRules[1]).style.cssText).toBe(
'flex-grow: 1; display: flex; flex-direction: column; overflow: hidden; --css-variable: 1px;'
'flex-grow: 1; display: flex; flex-direction: column; overflow: hidden; --css-variable: 1px; background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="), url("test.jpg");'
);

// CSSMediaRule
Expand Down
8 changes: 6 additions & 2 deletions packages/happy-dom/test/css/data/CSSParserInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default `
flex-direction: column;
overflow: hidden;
--css-variable: 1px;
background-image:
url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="),
url(test.jpg)
;
}
@media screen and (max-width: 36rem) {
Expand Down Expand Up @@ -58,7 +62,7 @@ export default `
color: red;
}
}
@supports (display: flex) {
.container {
color: green;
Expand All @@ -74,5 +78,5 @@ export default `
/* Single-line comment */
.foo { color: red; }
`.trim();
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,15 @@ describe('CSSStyleDeclaration', () => {
element.setAttribute('style', 'background-image: url(test.jpg), url(test2.jpg)');

expect(declaration.backgroundImage).toBe('url("test.jpg"), url("test2.jpg")');

element.setAttribute(
'style',
'background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=)'
);

expect(declaration.backgroundImage).toBe(
'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=")'
);
});
});

Expand Down

0 comments on commit ca9a7ac

Please sign in to comment.