From f87887a5579d689484fcee628d44b7454344ec87 Mon Sep 17 00:00:00 2001 From: David Ortner Date: Fri, 18 Aug 2023 11:29:40 +0200 Subject: [PATCH] #999@patch: Adds support for calc() in CSS values. --- .../property-manager/CSSStyleDeclarationValueParser.ts | 2 +- .../test/css/declaration/CSSStyleDeclaration.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/happy-dom/src/css/declaration/property-manager/CSSStyleDeclarationValueParser.ts b/packages/happy-dom/src/css/declaration/property-manager/CSSStyleDeclarationValueParser.ts index bc9ff1b1b..d05a8008d 100644 --- a/packages/happy-dom/src/css/declaration/property-manager/CSSStyleDeclarationValueParser.ts +++ b/packages/happy-dom/src/css/declaration/property-manager/CSSStyleDeclarationValueParser.ts @@ -262,7 +262,7 @@ export default class CSSStyleDeclarationValueParser { * @returns Parsed value. */ public static getMeasurement(value: string): string { - return this.getLength(value) || this.getPercentage(value); + return this.getLength(value) || this.getPercentage(value) || this.getCalc(value); } /** diff --git a/packages/happy-dom/test/css/declaration/CSSStyleDeclaration.test.ts b/packages/happy-dom/test/css/declaration/CSSStyleDeclaration.test.ts index 8f13e7216..0b4281e70 100644 --- a/packages/happy-dom/test/css/declaration/CSSStyleDeclaration.test.ts +++ b/packages/happy-dom/test/css/declaration/CSSStyleDeclaration.test.ts @@ -2103,6 +2103,14 @@ describe('CSSStyleDeclaration', () => { expect(declaration.width).toBe('0px'); }); + + it('Returns width for "width: calc(10% - 1px)".', () => { + const declaration = new CSSStyleDeclaration(element); + + element.setAttribute('style', 'width: calc(10% - 1px)'); + + expect(declaration.width).toBe('calc(10% - 1px)'); + }); }); describe('get height()', () => {