Skip to content

Commit

Permalink
Adds toString to CSSResult (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlouisse authored and justinfagnani committed Feb 4, 2019
1 parent 5637ce7 commit 0008b93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/css-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export class CSSResult {
}
return this._styleSheet;
}

toString(): String {
return this.cssText;
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/test/lit-element_styling_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,14 @@ suite('Static get styles', () => {
const div = el.shadowRoot!.querySelector('div');
assert.equal(getComputedStyle(div!).getPropertyValue('border-top-width').trim(), '4px');
});

test('`CSSResult` allows for String type coercion via toString()', async () => {
const cssModule = css`.my-module { color: yellow; }`;
// Coercion allows for reusage of css-tag outcomes in regular strings.
// Example use case: apply cssModule as global page styles at document.body level.
const bodyStyles = `${cssModule}`;
assert.equal(bodyStyles, '.my-module { color: yellow; }');
});
});

suite('ShadyDOM', () => {
Expand Down

0 comments on commit 0008b93

Please sign in to comment.