-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(testing): defineReadonlyEventProperty only if its not yet on the … #21944
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(testing): defineReadonlyEventProperty only if its not yet on the … #21944
Conversation
d79a351
to
3ea0462
Compare
@@ -46,7 +46,9 @@ export function createMouseEvent( | |||
|
|||
// IE won't set `defaultPrevented` on synthetic events so we need to do it manually. | |||
event.preventDefault = function() { | |||
defineReadonlyEventProperty(event, 'defaultPrevented', true); | |||
if(!event.defaultPrevented) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to also move the call to originalPreventDefault
up? That way non-IE browsers will never need to call defineReadonlyEventProperty
const result = originalPreventDefault();
if(!event.defaultPrevented) {
defineReadonlyEventProperty(event, 'defaultPrevented', true);
}
return result;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmalerba yes. that sounds reasonable. will update the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does your test fail if preventDefault
is called multiple times? My assumption was that it should be possible, because we're passing in configurable
into defineProperty
.
that non IE apps never call defineReadonlyEventProperty | ||
*/ | ||
const result = originalPreventDefault(); | ||
if (!event.defaultPrevented) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this mean that it could still fail if IE calls preventDefault
multiple times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - If preventDefault
is called then defaultPrevented
is true and the property will not be redefined. As you said it would also work if we call it with configurable: true
. By default configurable
is false.
Since we'll drop IE11 support for v13, we can remove this hack anyway. Closing in favor of #23394. Thanks for the contribution, and sorry it was on the backburner for some while. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
We have a project that uses CDK for testing Angular components. Some components are wrappers around a third-party library. We have a case where we need to pass down an event to a third-party component and are out of control how many times
preventDefault
is called. Currently, our test suite fails due to the CDK ifpreventDefault
is called multiple times.On each
preventDefault
call the CDK tries to redefine the read-only Event PropertydefaultPrevented
. In think that we should not fail on multiplepreventDefault
calls. From my point of view, it's not ideal to callpreventDefault
multiple times but also doesn't hurt.This fix only tries to redefine
defaultPrevented
if it doesn't exist on the event.