Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds toString to CSSResult #508

Merged
merged 1 commit into from
Feb 4, 2019
Merged
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
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be type string ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely. Good catch!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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