Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventTarget.prototype.addEventListener is not overridden #1902

Closed
bbonczek opened this issue Jan 18, 2019 · 5 comments · Fixed by #2203
Closed

EventTarget.prototype.addEventListener is not overridden #1902

bbonczek opened this issue Jan 18, 2019 · 5 comments · Fixed by #2203
Assignees
Labels
AREA: client FREQUENCY: critical STATE: Auto-locked Issues that were automatically locked by the Lock bot TYPE: bug
Milestone

Comments

@bbonczek
Copy link

What is your Test Scenario?

I'd like to test, whether screen size is bigger then 800px;

What is the Current behavior?

It works properly in regular browser (chrome without testcafe), but it does not when running testcafe test.

What is the Expected behavior?

My code should run consistently both in testcafe and in regular browser

What is your web application and your TestCafe test code?

https://github.com/bbonczek/testcafe-change-detection-issue

Steps to Reproduce:

You need to compare this app in regular browser and in testcafe browser. Clone repository and run
npm run install

Next thing you want to do is run application in normal browser. You can do it by running
npm run start
and navigating to localhost:4200

try to resize window, to change it's height - you should see value switching beetween true and false:

working case in chrome browser

You can see mp4 version here: https://ezgif.com/video-to-gif/ezgif-2-271f5333a3b8.mp4

Now let's try to do the same, but in testcafe test. Don't stop dev server. Open other console and run
npm run testcafe

Test will go into debug just after page loads. Click Unlock Page and try resizing again- this time nothing will happen:
not working case in testcafe chrome browser
mp4 version is here:
https://ezgif.com/video-to-gif/ezgif-2-37d0daf5224f.mp4

Your Environment details:

  • testcafe version: 0.23.3
  • node.js version: v10.14.1
  • command-line arguments: testcafe chrome e2e/testcafe-buggy-test.test.js
  • browser name and version: Chrome 71.0.3578.98
  • platform and version: Windows 10
@Farfurix
Copy link
Contributor

Hello, @bbonczek.
Thank you for your detailed description. I've reproduced this issue. Our team will research it and check for a suitable solution.

@AndreyBelym AndreyBelym transferred this issue from DevExpress/testcafe Jan 18, 2019
@Farfurix Farfurix added this to the Planned milestone Jan 18, 2019
@Farfurix Farfurix self-assigned this Jan 23, 2019
@Farfurix
Copy link
Contributor

The issue seems to be connected to the EventTarget method patch:
webpack:///./node_modules/zone.js/dist/zone.js

function patchEventTargetMethods(obj, patchOptions)
...
    // proto: EventTarget {addEventListener: ƒ, removeEventListener: ƒ, dispatchEvent: ƒ, __zone_symbol__addEventListener: ƒ, __zone_symbol__removeEventListener: ƒ, …}
    proto[ADD_EVENT_LISTENER] = makeAddListener(nativeAddEventListener, ADD_EVENT_LISTENER_SOURCE, customSchedule, customCancel, returnTarget);

The test below is based on Chrome's native behavior:

if (!browserUtils.isIE11) {
    test('patch EventTarget methods on the client side (GH-1902)', function () {
        var savedMeth   = window.EventTarget.prototype.addEventListener;
        var xhr         = new XMLHttpRequest();
        var patchedMeth = function () {
            return 'patched';
        };

        strictEqual(window.addEventListener, window.EventTarget.prototype.addEventListener);
        strictEqual(window.document.addEventListener, window.EventTarget.prototype.addEventListener);
        strictEqual(window.document.body.addEventListener, window.EventTarget.prototype.addEventListener);
        strictEqual(Object.getPrototypeOf(xhr).addEventListener, window.EventTarget.prototype.addEventListener);

        window.EventTarget.prototype.addEventListener = patchedMeth;

        strictEqual(window.addEventListener, patchedMeth);
        strictEqual(window.document.addEventListener, patchedMeth);
        strictEqual(window.document.body.addEventListener, patchedMeth);


        strictEqual(Object.getPrototypeOf(xhr).addEventListener, patchedMeth);

        window.EventTarget.prototype.addEventListener = savedMeth;
    });
}

We will consider fixing this issue in future sprints.

@LavrovArtem LavrovArtem modified the milestones: Planned, Sprint #28 Feb 15, 2019
@LavrovArtem LavrovArtem modified the milestones: Sprint #28, Sprint #29 Mar 13, 2019
@LavrovArtem LavrovArtem modified the milestones: Sprint #29, Sprint #30 Mar 21, 2019
@LavrovArtem LavrovArtem modified the milestones: Sprint #30, Sprint #31 Apr 2, 2019
@Farfurix Farfurix removed their assignment Apr 11, 2019
@LavrovArtem LavrovArtem modified the milestones: Sprint #31, Sprint #32 Apr 22, 2019
@LavrovArtem LavrovArtem modified the milestones: Sprint #32, Sprint #33 May 14, 2019
@LavrovArtem LavrovArtem modified the milestones: Sprint #33, Sprint #34 May 29, 2019
@LavrovArtem LavrovArtem modified the milestones: Sprint #34, Sprint #35 Jun 17, 2019
@LavrovArtem LavrovArtem modified the milestones: Sprint #35, Planned Jul 3, 2019
@LavrovArtem LavrovArtem changed the title Window resize event is not working when running testcafe test. EventTarget.prototype.addEventListener is not overridden Sep 10, 2019
@LavrovArtem
Copy link
Contributor

Same problem on this site with Angular.

@AndreyBelym AndreyBelym modified the milestones: Planned, Sprint #42 Sep 24, 2019
@AndreyBelym AndreyBelym modified the milestones: Sprint #42, Sprint #43 Oct 8, 2019
@AndreyBelym AndreyBelym modified the milestones: Sprint #43, Sprint #44 Oct 22, 2019
@Farfurix Farfurix self-assigned this Oct 25, 2019
@LavrovArtem LavrovArtem modified the milestones: Sprint #44, Sprint #45 Nov 5, 2019
@LavrovArtem LavrovArtem modified the milestones: Sprint #45, Sprint #46 Nov 20, 2019
@AndreyBelym AndreyBelym modified the milestones: Sprint #46, Sprint #47 Dec 4, 2019
@LavrovArtem LavrovArtem modified the milestones: Sprint #47, Sprint #48 Dec 19, 2019
@AndreyBelym AndreyBelym modified the milestones: Sprint #48, Sprint #49 Jan 10, 2020
@AndreyBelym AndreyBelym modified the milestones: Sprint #49, Sprint #50 Jan 27, 2020
Farfurix added a commit that referenced this issue Feb 5, 2020
…1902) (#2203)

* Fix 'EventTarget.prototype.addEventListener is not overridden' (close #1902)

* rewrite "template literals" as string concatenation

* Refactror: _getNativeAddEventListener, _getNativeRemoveEventListener

* Fix the "SVGElement.dispatchEvent should be overriden" test

* eventTargetDispatchEvent, native XHR

* xhr event methods, refactor

* Add the `dispatchEvent` test case

* Fix review 1

* Combine IE and non-IE cases

* Naming, requested changes

* Requested changes, naming

* Requested changes

* Fix comment
@Farfurix
Copy link
Contributor

Farfurix commented Feb 5, 2020

Wait for DevExpress/testcafe#4614

@lock
Copy link

lock bot commented Feb 15, 2020

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

@lock lock bot added the STATE: Auto-locked Issues that were automatically locked by the Lock bot label Feb 15, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Feb 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
AREA: client FREQUENCY: critical STATE: Auto-locked Issues that were automatically locked by the Lock bot TYPE: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants