diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2024-12-16 19:00:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-16 19:00:50 +0100 |
commit | 4466770992d5833358169d0248c4deedadea1a96 (patch) | |
tree | 8b93b72377872d9cde5478f7ce7e7327f6413cc1 /test | |
parent | 0e123509d529456ddf130abb97e6266b53f62c50 (diff) | |
download | jquery-main.tar.gz jquery-main.zip |
Sizzle & the `3.x-stable` branch have tests adding a custom attribute getter
to `attrHandle` and checking if selection takes it into account. `attrHandle`
was removed from the `4.x` line so the tests were not ported to the `main`
branch, but the `4.x` line takes standard jQuery attribute getters into account
instead and we should test for that.
Backport the `3.x-stable` selector tests for custom attribute getters, changing
`jQuery.expr.attrHandle` to `jQuery.attrHooks`.
Closes gh-5568
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/selector.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/unit/selector.js b/test/unit/selector.js index 1c3358254..5fecfae94 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -2237,6 +2237,37 @@ QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "custom pseudos", function( as } } ); +QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "custom attribute getters", function( assert ) { + assert.expect( 2 ); + + var original = jQuery.attrHooks.hreflang, + selector = "a:contains('mozilla')[hreflang='https://mozilla.org/en']"; + + try { + jQuery.attrHooks.hreflang = { + get: function( elem, name ) { + var href = elem.getAttribute( "href" ), + lang = elem.getAttribute( name ); + return lang && ( href + lang ); + } + }; + + assert.deepEqual( + jQuery.find( selector, createWithFriesXML() ), + [], + "Custom attrHooks (preferred document)" + ); + assert.t( "Custom attrHooks (preferred document)", selector, [ "mozilla" ] ); + } finally { + jQuery.attrHooks.hreflang = original; + } +} ); +QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "Ensure no 'undefined' handler is added", function( assert ) { + assert.expect( 1 ); + assert.ok( !jQuery.attrHooks.hasOwnProperty( "undefined" ), + "Extra attr handlers are not added to jQuery.attrHooks (https://github.com/jquery/sizzle/issues/353)" ); +} ); + QUnit.test( "jQuery.find.matchesSelector", function( assert ) { assert.expect( 15 ); |