From 1548047aa8c230758ebdbef2aca887b6aa500ee4 Mon Sep 17 00:00:00 2001 From: Matt Schile Date: Mon, 27 Jan 2025 09:37:26 -0700 Subject: [PATCH] fix: non-HTMLElement(s) fail during assertions (#30947) --- cli/CHANGELOG.md | 1 + packages/driver/cypress/e2e/commands/assertions.cy.js | 11 +++++++++++ packages/driver/src/dom/visibility.ts | 8 +++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index c14b23524845..73d348db324e 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -6,6 +6,7 @@ _Released 1/28/2025 (PENDING)_ **Bugfixes:** - Fixed an issue where Cypress would incorrectly navigate to `about:blank` when test isolation was disabled and the last test would fail and then retry. Fixes [#28527](https://github.com/cypress-io/cypress/issues/28527). +- Fixed an issue where non-HTMLElement(s) may fail during assertions. Fixes [#30944](https://github.com/cypress-io/cypress/issues/30944) **Misc:** diff --git a/packages/driver/cypress/e2e/commands/assertions.cy.js b/packages/driver/cypress/e2e/commands/assertions.cy.js index 3da8fa44a2fe..e13b1da54ab1 100644 --- a/packages/driver/cypress/e2e/commands/assertions.cy.js +++ b/packages/driver/cypress/e2e/commands/assertions.cy.js @@ -939,6 +939,17 @@ describe('src/cy/commands/assertions', () => { expect(2n).to.equal(2n) }) + it('handles non-HTMLElement(s) (e.g. Element)', () => { + const xml = 'Bar' + const parser = new DOMParser() + const doc = parser.parseFromString(xml, 'application/xml') + const foo = doc.getElementsByTagName('foo')[0] + + expect(foo).not.to.be.undefined + expect(foo).to.be.instanceOf(Element) + expect(foo).not.to.be.instanceOf(HTMLElement) + }) + it('#consoleProps for regular objects', (done) => { cy.on('log:added', (attrs, log) => { if (attrs.name === 'assert') { diff --git a/packages/driver/src/dom/visibility.ts b/packages/driver/src/dom/visibility.ts index f9373dc6d75a..a2f2246d3f40 100644 --- a/packages/driver/src/dom/visibility.ts +++ b/packages/driver/src/dom/visibility.ts @@ -130,13 +130,11 @@ const elHasNoEffectiveWidthOrHeight = ($el: JQuery) => { // display:none elements, and generally any elements that are not directly rendered, // an empty list is returned. const el = $el[0] - let transform - if ($el[0].style.transform) { - const style = getComputedStyle(el) + const style = getComputedStyle(el) + let transform = style.getPropertyValue('transform') - transform = style.getPropertyValue('transform') - } else { + if (!transform.length) { transform = 'none' }