Skip to content

Commit

Permalink
feat: add CSSStyleSheet.prototype.media
Browse files Browse the repository at this point in the history
  • Loading branch information
Lodin authored and calebdwilliams committed Jan 30, 2022
1 parent ebbd780 commit e6c5177
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ConstructedStyleSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ defineProperty(proto, 'cssRules', {
},
});

defineProperty(proto, 'media', {
configurable: true,
enumerable: true,
get: function media() {
// CSSStyleSheet.prototype.media;
checkInvocationCorrectness(this);

return $basicStyleElement.get(this)!.sheet!.media;
},
});

cssStyleSheetMethods.forEach((method) => {
proto[method] = function () {
const self = this;
Expand Down
7 changes: 7 additions & 0 deletions test/polyfill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('Constructible Style Sheets polyfill', () => {
describe('basic', () => {
it('has replace and replaceSync methods', () => {
expect(sheet.cssRules).toBeDefined();
expect(sheet.media).toBeDefined();
expect(sheet.replace).toBeDefined();
expect(sheet.replaceSync).toBeDefined();
});
Expand Down Expand Up @@ -99,6 +100,12 @@ describe('Constructible Style Sheets polyfill', () => {
illegalPattern,
);
});

it('media', () => {
expect(() => CSSStyleSheet.prototype.media).toThrowError(
illegalPattern,
);
});
});
});

Expand Down

0 comments on commit e6c5177

Please sign in to comment.