Accessing private class members got rewritten by Hammerhead causing getting undefined on a defined member
pokai-chang-appier opened this issue · 3 comments
What is your Scenario?
(Similar to #2858, but with a different JS feature)
We are using private class members in our JavaScript code, such as the following:
class SomeClass {
#somePrivateAttr = 'hi';
getPrivateAttr() {
return this.#somePrivateAttr;
}
}
const someClass = new SomeClass();
alert('This should be "hi": ' + someClass.getPrivateAttr());
It should show alert This should be “hi”: hi
when executed.
However, when proxied via testcafe-hammerhead
, the line:
this.#somePrivateAttr
got re-written as:
__get$(this,”somePrivateAttr”)
which will get undefined
instead of 'hi'
.
What is the Current behavior?
this.#somePrivateAttr
got re-written as __get$(this,”somePrivateAttr”)
which become undefined
.
What is the Expected behavior?
Proxied code should get this.#somePrivateAttr
as 'hi'
correctly.
What is your public website URL? (or attach your complete example)
https://moonlit-kangaroo-fd48ff.netlify.app/index.html
What is your TestCafe test code?
N/A
Your complete configuration file
No response
Your complete test report
No response
Screenshots
No response
Steps to Reproduce
To reproduce, I prepared a simple web page, https://moonlit-kangaroo-fd48ff.netlify.app.
The HTML:
<!-- https://moonlit-kangaroo-fd48ff.netlify.app/index.html -->
<script src="script.js"></script>
JS:
// https://moonlit-kangaroo-fd48ff.netlify.app/script.js
class SomeClass {
#somePrivateAttr = 'hi';
getPrivateAttr() {
return this.#somePrivateAttr;
}
}
const someClass = new SomeClass();
alert('This should be "hi": ' + someClass.getPrivateAttr());
When opening this page, an alert will pop-up with This should be "hi": hi
:
But while opening the page in the Hammerhead playground, as instructed in the README, the message becomes This should be "hi": undefined
TestCafe version
testcafe-hammerhead 44388ee
Node.js version
v18.15.0
Command-line arguments
N/A
Browser name(s) and version(s)
No response
Platform(s) and version(s)
No response
Other
No response
I was able to workaround this by using --experimental-proxyless
.
We plan to add the fix to testcafe version 2.5.1. While we are preparing it you can try the release candidate version 2.5.1-rc.1 with the fix.
duplicate of DevExpress/testcafe#7632