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

fix: fix flaky test cases of passive events #35679

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 17 additions & 10 deletions packages/zone.js/test/browser/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,19 @@ describe('Zone', function() {
scrollEvent.initEvent('scroll', true, true);

const zone = Zone.current.fork({name: 'run'});
const div = document.createElement('div');
document.body.appendChild(div);

Zone.current.fork({name: 'scroll'}).run(() => {
document.addEventListener(
'scroll', () => { expect(Zone.current.name).toEqual(zone.name); });
const listener = () => {
expect(Zone.current.name).toEqual(zone.name);
div.removeEventListener('scroll', listener);
};
div.addEventListener('scroll', listener);
});

zone.run(() => { document.dispatchEvent(scrollEvent); });
(document as any).removeAllListeners('scroll');
zone.run(() => { div.dispatchEvent(scrollEvent); });
document.body.removeChild(div);
});

it('should be able to clear on handler added before load zone.js', function() {
Expand Down Expand Up @@ -1047,12 +1052,16 @@ describe('Zone', function() {
const testPassive = function(eventName: string, expectedPassiveLog: string, options: any) {
(button as any).addEventListener(eventName, listener, options);
const evt = document.createEvent('Event');
evt.initEvent(eventName, true, true);
evt.initEvent(eventName, false, true);
button.dispatchEvent(evt);
expect(logs).toEqual(['default will run', expectedPassiveLog]);
(button as any).removeAllListeners(eventName);
};
beforeEach(() => { logs = []; });
beforeEach(() => {
logs = [];
(button as any).removeAllListeners();
});
afterEach(() => { (button as any).removeAllListeners(); });
it('should be passive with global variable defined',
() => { testPassive('touchstart', 'default will run', {passive: true}); });
it('should not be passive without global variable defined',
Expand All @@ -1065,10 +1074,8 @@ describe('Zone', function() {
() => { testPassive('touchstart', 'default will run', true); });
it('should not be passive with global variable defined with passive false option',
() => { testPassive('touchstart', 'defaultPrevented', {passive: false}); });
it('should be passive with global variable defined and also blacklisted', () => {
(document as any).removeAllListeners('scroll');
testPassive('scroll', 'default will run', undefined);
});
it('should be passive with global variable defined and also blacklisted',
() => { testPassive('scroll', 'default will run', undefined); });
it('should not be passive without global variable defined and also blacklisted',
() => { testPassive('wheel', 'defaultPrevented', undefined); });
});
Expand Down