Skip to content

Commit 6faa5f2

Browse files
authored
fix(mock-doc): allow urls as css values (#2857)
css values such as `background-image: (https://mydomain.com/image.jpg)` currently lose values after the second colon. This ensures the entire value is taken into account when a url is specified.
1 parent c7b07c6 commit 6faa5f2

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/mock-doc/css-style-declaration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class MockCSSStyleDeclaration {
4747
const splt = rule.split(':');
4848
if (splt.length > 1) {
4949
const prop = splt[0].trim();
50-
const value = splt[1].trim();
50+
const value = splt.slice(1).join(':').trim();
5151
if (prop !== '' && value !== '') {
5252
this._styles.set(jsCaseToCssCase(prop), value);
5353
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { MockCSSStyleDeclaration } from '../css-style-declaration';
2+
import { MockDocument } from '../document';
3+
import { MockHTMLElement } from '../node';
4+
5+
describe('css-style-declaration', () => {
6+
let doc: MockDocument;
7+
beforeEach(() => {
8+
doc = new MockDocument();
9+
});
10+
11+
it('should set attributes correctly', () => {
12+
const cssAttr = new MockCSSStyleDeclaration();
13+
cssAttr.cssText = 'color: red';
14+
15+
expect(cssAttr.cssText).toBe('color: red;');
16+
});
17+
18+
it('should handle attributes containing colons', () => {
19+
const cssAttr = new MockCSSStyleDeclaration();
20+
cssAttr.cssText = 'background-image: (https://ionic.io/img/ionic-io-og-img.png);';
21+
22+
expect(cssAttr.cssText).toBe('background-image: (https://ionic.io/img/ionic-io-og-img.png);');
23+
});
24+
25+
it('should set styles on html elements', () => {
26+
const element = new MockHTMLElement(doc, 'div');
27+
element.style = 'color: red; font-family: "My Custom Font"';
28+
29+
expect(element.style.cssText).toEqual('color: red; font-family: "My Custom Font";');
30+
expect(element.style.cssText).toEqual(element.getAttribute('style'));
31+
});
32+
});

0 commit comments

Comments
 (0)