]> source.dussan.org Git - jquery.git/commitdiff
Tests: ensure that module assertions run on supported browsers
authorTimmy Willison <4timmywil@gmail.com>
Tue, 16 Jan 2018 20:18:32 +0000 (15:18 -0500)
committerTimmy Willison <4timmywil@gmail.com>
Tue, 16 Jan 2018 20:18:32 +0000 (15:18 -0500)
- Also fixes tests for karma, where the URL for the module is different

Ref gh-3871

test/data/inner_module.js
test/data/testinit.js
test/unit/manipulation.js

index a89a39d27a3f9721f7809aab910552f4f2b419ef..7f359ed9588b78c118522d3961282e5c2db608ae 100644 (file)
@@ -1 +1 @@
-window.ok( true, "evaluated: innert module with src" );
+window.ok( true, "evaluated: inner module with src" );
index 211824a8901dda36c24edbaa6303f782945c2b15..a91e59b6accacb12a547ccc8eb9aecf5414c97e2 100644 (file)
@@ -284,7 +284,17 @@ if ( window.__karma__ ) {
 QUnit.isSwarm = ( QUnit.urlParams.swarmURL + "" ).indexOf( "http" ) === 0;
 QUnit.basicTests = ( QUnit.urlParams.module + "" ) === "basic";
 
+// Async test for module script type support
+function moduleTypeSupported() {
+       var script = document.createElement( "script" );
+       script.type = "module";
+       script.text = "QUnit.moduleTypeSupported = true";
+       document.head.appendChild( script ).parentNode.removeChild( script );
+}
+moduleTypeSupported();
+
 this.loadTests = function() {
+
        // Get testSubproject from testrunner first
        require( [ "data/testrunner.js" ], function() {
                var i = 0,
index bfe41ed4ec33d9690abe6b0e7d905117d8fab137..660dad773b30bc88cdc769e53ea16da899b61731 100644 (file)
@@ -1797,20 +1797,26 @@ QUnit.test( "html(Function)", function( assert ) {
        testHtml( manipulationFunctionReturningObj, assert  );
 } );
 
-QUnit.test( "html(script type module)", function( assert ) {
-       assert.expect( 1 );
-       var fixture = jQuery( "#qunit-fixture" ),
-       tmp = fixture.html(
+QUnit[ QUnit.moduleTypeSupported ? "test" : "skip" ]( "html(script type module)", function( assert ) {
+       assert.expect( 4 );
+       var done = assert.async(),
+               $fixture = jQuery( "#qunit-fixture" );
+
+       $fixture.html(
                [
                        "<script type='module'>ok( true, 'evaluated: module' );</script>",
-                       "<script type='module' src='./data/module.js'></script>",
+                       "<script type='module' src='" + url( "module.js" ) + "'></script>",
                        "<div>",
                                "<script type='module'>ok( true, 'evaluated: inner module' );</script>",
-                               "<script type='module' src='./data/inner_module.js'></script>",
+                               "<script type='module' src='" + url( "inner_module.js" ) + "'></script>",
                        "</div>"
                ].join( "" )
-       ).find( "script" );
-       assert.equal( tmp.length, 4, "All script tags remain." );
+       );
+
+       // Allow asynchronous script execution to generate assertions
+       setTimeout( function() {
+               done();
+       }, 1000 );
 } );
 
 QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) {