diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2022-06-28 12:39:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-28 12:39:01 +0200 |
commit | fae5fee8b435cc20352d28b0a384b9784b1ad9ed (patch) | |
tree | 86ae9425c469a476c25ce62399297d35472dbc2c /test/unit/basic.js | |
parent | 52f452b2e8881e5ec5c9e880e277c8ecf633e8dc (diff) | |
download | jquery-fae5fee8b435cc20352d28b0a384b9784b1ad9ed.tar.gz jquery-fae5fee8b435cc20352d28b0a384b9784b1ad9ed.zip |
Tests: Exclude tests based on compilation flags, not API presence
Introduces a new test API, `includesModule`. The method returns whether
a particular module like "ajax" or "deprecated" is included in the current
jQuery build; it handles the slim build as well. The util was created so that
we don't treat presence of particular APIs to decide whether to run a test as
then if we accidentally remove an API, the tests would still not fail.
Fixes gh-5069
Closes gh-5046
Diffstat (limited to 'test/unit/basic.js')
-rw-r--r-- | test/unit/basic.js | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/test/unit/basic.js b/test/unit/basic.js index fc3f8e589..ca7d947e6 100644 --- a/test/unit/basic.js +++ b/test/unit/basic.js @@ -1,6 +1,6 @@ QUnit.module( "basic", { afterEach: moduleTeardown } ); -if ( jQuery.ajax ) { +if ( includesModule( "ajax" ) ) { QUnit.test( "ajax", function( assert ) { assert.expect( 4 ); @@ -33,6 +33,7 @@ QUnit.test( "ajax", function( assert ) { } ); } +if ( includesModule( "attributes" ) ) { QUnit.test( "attributes", function( assert ) { assert.expect( 6 ); @@ -51,8 +52,9 @@ QUnit.test( "attributes", function( assert ) { assert.strictEqual( input.val( "xyz" ).val(), "xyz", ".val getter/setter" ); } ); +} -if ( jQuery.css ) { +if ( includesModule( "css" ) ) { QUnit.test( "css", function( assert ) { assert.expect( 1 ); @@ -62,7 +64,7 @@ QUnit.test( "css", function( assert ) { } ); } -if ( jQuery.fn.show && jQuery.fn.hide ) { +if ( includesModule( "css" ) ) { QUnit.test( "show/hide", function( assert ) { assert.expect( 2 ); @@ -123,6 +125,7 @@ QUnit.test( "core", function( assert ) { 2, "jQuery.parseHTML" ); } ); +if ( includesModule( "data" ) ) { QUnit.test( "data", function( assert ) { assert.expect( 4 ); @@ -133,7 +136,9 @@ QUnit.test( "data", function( assert ) { assert.strictEqual( elem.data( "c" ), "d", ".data from data-* attributes" ); assert.ok( jQuery.hasData( elem[ 0 ] ), "jQuery.hasData - true" ); } ); +} +if ( includesModule( "dimensions" ) ) { QUnit.test( "dimensions", function( assert ) { assert.expect( 3 ); @@ -145,7 +150,9 @@ QUnit.test( "dimensions", function( assert ) { assert.strictEqual( elem.innerWidth(), 64, ".innerWidth getter" ); assert.strictEqual( elem.outerWidth(), 68, ".outerWidth getter" ); } ); +} +if ( includesModule( "event" ) ) { QUnit.test( "event", function( assert ) { assert.expect( 1 ); @@ -162,7 +169,9 @@ QUnit.test( "event", function( assert ) { } ) .trigger( "click" ); } ); +} +if ( includesModule( "manipulation" ) ) { QUnit.test( "manipulation", function( assert ) { assert.expect( 5 ); @@ -195,6 +204,9 @@ QUnit.test( "manipulation", function( assert ) { ".after/.before" ); } ); +} + +if ( includesModule( "offset" ) ) { // Support: jsdom 13.2+ // jsdom returns 0 for offset-related properties @@ -208,6 +220,7 @@ QUnit[ /jsdom\//.test( navigator.userAgent ) ? "skip" : "test" ]( "offset", func assert.strictEqual( elem.position().top, 5, ".position getter" ); assert.strictEqual( elem.offsetParent()[ 0 ], parent[ 0 ], ".offsetParent" ); } ); +} QUnit.test( "selector", function( assert ) { assert.expect( 2 ); @@ -219,6 +232,7 @@ QUnit.test( "selector", function( assert ) { assert.strictEqual( elem.find( "span.b a" )[ 0 ].nodeName, "A", ".find - one result" ); } ); +if ( includesModule( "serialize" ) ) { QUnit.test( "serialize", function( assert ) { assert.expect( 2 ); @@ -232,6 +246,7 @@ QUnit.test( "serialize", function( assert ) { "&select1=&select2=3&select3=1&select3=2&select5=3", "form serialization as query string" ); } ); +} QUnit.test( "traversing", function( assert ) { assert.expect( 12 ); @@ -253,6 +268,7 @@ QUnit.test( "traversing", function( assert ) { assert.strictEqual( elem.contents()[ 3 ].nodeType, 3, ".contents" ); } ); +if ( includesModule( "wrap" ) ) { QUnit.test( "wrap", function( assert ) { assert.expect( 3 ); @@ -283,3 +299,4 @@ QUnit.test( "wrap", function( assert ) { ); } ); +} |