SpecialJavaScriptTest: Make sure we don't catch our own exception
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 27 Apr 2017 18:22:41 +0000 (20:22 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 27 Apr 2017 18:22:41 +0000 (20:22 +0200)
If the jQuery promise returned by mw.loader.using() is rejected
synchronously (e.g. because one of the modules has a dependency on
non-existent module), the function passed to fail() also executes
synchronously. Note that this is true also with jQuery 3.

The exception it throws was caught by the catch() below, which
resulted in start() being called twice, which resulted in QUnit
throwing 'Uncaught Error: Called start() outside of a test
context too many times' rather than actually starting.

Change-Id: I5c6b50647c0af0fdec6547aaa59165f6b4a42642

includes/specials/SpecialJavaScriptTest.php

index 52064b7..17c64c8 100644 (file)
@@ -143,7 +143,11 @@ class SpecialJavaScriptTest extends SpecialPage {
                        .always( function () {
                                start();
                        } )
                        .always( function () {
                                start();
                        } )
-                       .fail( function ( e ) { throw e; } );
+                       .fail( function ( e ) {
+                               setTimeout( function () {
+                                       throw e;
+                               } );
+                       } );
        } catch ( e ) {
                start();
                throw e;
        } catch ( e ) {
                start();
                throw e;