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

Tests: Account for an extra noop focus/blur listener in jQuery >=3.4 #1945

Merged
merged 1 commit into from
Feb 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Tests: Account for an extra noop focus/blur listener in jQuery >=3.4
jQuery >=3.4.0 uses a special focus/blur handler pair needed to fix various
issues with checkboxes/radio buttons as well as being able to pass data in focus
triggers. This leaves extra focus & blur events if any of these events were ever
listened to at a particular element.

We've started skipping these handlers in the `domEqual` assertion in gh-1930 but
we missed a case where an event is triggered before any handler is attached -
jQuery >=3.4.0 attaches then an extra noop listener just to force the code path
to go through the setup code before the trigger happens. We now skip this extra
handler as well.

This fixes a test failure in "dialog: methods" destroy tests.

Ref jquery/jquery#4496
Ref gh-1930
  • Loading branch information
mgol committed Feb 19, 2021
commit e5208e96b19d52ecd14a9dbc3bf5fc402600a1ce
43 changes: 22 additions & 21 deletions tests/lib/qunit-assert-domequal.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,34 +145,35 @@ function extract( selector, message ) {
// data comparisons in tests.
// See https://github.com/jquery/jquery/issues/4496
if ( result.events && jQueryVersionSince( "3.4.0" ) ) {
var i, eventDataList, eventData;
$.each( [ "focus", "blur" ], function( index, eventType ) {
if ( !result.events[ eventType ] ) {
return;
}

// Only the special internal handlers
// have the namespace field set to boolean `false`;
// filter them out.
result.events[ eventType ] = result.events[ eventType ].filter( function( eventData ) {
return eventData.namespace !== false;
} );

eventDataList = result.events[ eventType ];
for ( i = eventDataList.length - 1; i > -1; i-- ) {
eventData = eventDataList[ i ];

// Only these special jQuery internal handlers
// have the `namespace` field set to `false`;
// all other events use a string value, possibly
// an empty string if no namespace was set.
if ( eventData.namespace === false ) {
eventDataList.splice( i, 1 );
}
}
// Filter special jQuery focus-related handlers out.
result.events[ eventType ] = result.events[ eventType ]
.filter( function( eventData ) {
var handlerBody = eventData.handler.toString().replace(
/^[^{]+\{[\s\n]*((?:.|\n)*?)\s*;?\s*\}[^}]*$/,
"$1"
);

// Only these special jQuery internal handlers
// have the `namespace` field set to `false`;
// all other events use a string value, possibly
// an empty string if no namespace was set.
return eventData.namespace !== false &&

// If a focus event was triggered without adding a handler first,
// jQuery attaches an empty handler at the beginning of a trigger
// call. Ignore this handler as well; it's a function with just
// `return true;` in the body.
// Handle the minified version as well.
handlerBody !== "return true" && handlerBody !== "return!0";
} );

// Remove empty eventData collections to follow jQuery behavior.
if ( !eventDataList.length ) {
if ( !result.events[ eventType ].length ) {
delete result.events[ eventType ];
}
} );
Expand Down