🐛 Bug: Mocha adds forEach property to CSSStyleDeclaration, at least inside a Proxy #4423
Open
4 tasks done
Labels
area: browser
browser-specific
status: accepting prs
Mocha can use your help with this one!
type: bug
a defect, confirmed by a maintainer
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
Since mocha 8.1.0, CSSStyleDeclaration has a forEach property, at least inside a Proxy.
This is not the case in mocha 8.0.1.
Steps to Reproduce
Checkout edwinm/carbonium@0ea6c45 :
Run
npm i
Run
npm test
All test pass
Install mocha 8.0.1:
npm i @types/[email protected] [email protected]
In
src/carbonium.ts
on line 146, change-- if ("forEach" in target && !(target instanceof CSSStyleDeclaration)) {
to
++ if ("forEach" in target) {
Now my bugfix is removed.
Run
npm test
. All tests pass.Install mocha 8.1.0:
npm i [email protected]
Run
npm test
.Actual behavior:
One test fails.
Expected behavior:
All tests pass.
Reproduces how often:
Always.
Context
Cambrium is like jQuery. It uses Proxy to merge a list of elements and element properties together.
It uses
"forEach" in target
to see whether we're dealing with a list of elements or element properties.This test fails in mocha when it encouters
element.style
, becauseCSSStyleDeclaration
now also has aforEach
property.I fixed this by also checking for
target instanceof CSSStyleDeclaration
.It is still strange that in mocha 8.1.0, CSSStyleDeclaration suddenly has a
forEach
property.This is a fringe issue and fixed on my end. The bug might still trigger problems in other (not fringe) code
and it seems like a good idea to figure out why this happens.
Versions
npx mocha --version
andnode node_modules/.bin/mocha --version
:both 8.1.0 (same bug in 8.1.2)
node --version
:v14.5.0
macOS Catalina 10.15.6
64
zsh
Chrome, Firefox
TypeScript 3.9.7
The text was updated successfully, but these errors were encountered: