jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/348133 )

Change subject: tests: Use assert.async() instead of QUnit.stop/start
......................................................................


tests: Use assert.async() instead of QUnit.stop/start

* Remove use of undocumented 'this' inside promise callback,
  use the promise variable instead.
* Remove needless expectCount.

Change-Id: I3a698207440d8085a502fa54da8bb5feddfa1dcb
---
M modules/ext.templateDataGenerator.sourceHandler.js
M tests/ext.templateData.tests.js
2 files changed, 14 insertions(+), 42 deletions(-)

Approvals:
  jenkins-bot: Verified
  Jforrester: Looks good to me, approved



diff --git a/modules/ext.templateDataGenerator.sourceHandler.js 
b/modules/ext.templateDataGenerator.sourceHandler.js
index dd23ff8..55f11ee 100644
--- a/modules/ext.templateDataGenerator.sourceHandler.js
+++ b/modules/ext.templateDataGenerator.sourceHandler.js
@@ -196,7 +196,7 @@
        if ( parts && parts[ 1 ] && $.trim( parts[ 1 ] ).length > 0 ) {
                // Parse the json string
                try {
-                       return $.parseJSON( $.trim( parts[ 1 ] ) );
+                       return JSON.parse( $.trim( parts[ 1 ] ) );
                } catch ( err ) {
                        return null;
                }
diff --git a/tests/ext.templateData.tests.js b/tests/ext.templateData.tests.js
index 8006c59..d32fb29 100644
--- a/tests/ext.templateData.tests.js
+++ b/tests/ext.templateData.tests.js
@@ -345,13 +345,6 @@
                        }
                };
 
-               QUnit.expect(
-                       tests.compare.length +
-                       tests.splitAndTrimArray.length +
-                       tests.arrayUnionWithoutEmpty.length +
-                       Object.keys( tests.props ).length
-               );
-
                // Compare
                for ( i = 0; i < tests.compare.length; i++ ) {
                        testVars = tests.compare[ i ];
@@ -396,7 +389,7 @@
        } );
 
        // Test model load
-       QUnit.asyncTest( 'TemplateData model', function ( assert ) {
+       QUnit.test( 'TemplateData model', function ( assert ) {
                var i,
                        sourceHandler = new mw.TemplateData.SourceHandler(),
                        paramAddTest = [
@@ -501,20 +494,7 @@
                                }
                        ];
 
-               QUnit.expect(
-                       // Description and parameter list
-                       3 +
-                       // Add parameter tests
-                       2 * paramAddTest.length +
-                       // Change properties tests
-                       paramChangeTest.length +
-                       // Format tests
-                       8 +
-                       // Json output
-                       3
-               );
-
-               sourceHandler.buildModel( originalWikitext )
+               return sourceHandler.buildModel( originalWikitext )
                        .done( function ( model ) {
 
                                // Check description
@@ -615,14 +595,11 @@
                                        'Final templatedata output with 
paramOrder'
                                );
 
-                       } )
-                       .always( function () {
-                               QUnit.start();
                        } );
        } );
 
        // Test model fail
-       QUnit.asyncTest( 'TemplateData sourceHandler', function ( assert ) {
+       QUnit.test( 'TemplateData sourceHandler', function ( assert ) {
                var sourceHandler = new mw.TemplateData.SourceHandler(),
                        erronousString = '<templatedata>{\n' +
                                '       "params": {\n' +
@@ -645,19 +622,19 @@
                                '                       "suggested": true\n' +
                                '               }\n' +
                                '       }\n' +
-                               '}</templatedata>';
+                               '}</templatedata>',
+                       done = assert.async(),
+                       promise;
 
-               QUnit.expect( 1 );
-
-               sourceHandler.buildModel( erronousString )
-                       .always( function () {
-                               assert.strictEqual( this.state(), 'rejected', 
'Promise rejected on erronous json string.' );
-                               QUnit.start();
-                       } );
+               promise = sourceHandler.buildModel( erronousString );
+               promise.always( function () {
+                       assert.strictEqual( promise.state(), 'rejected', 
'Promise rejected on erronous json string.' );
+                       done();
+               } );
        } );
 
        // Test model gets default format
-       QUnit.asyncTest( 'TemplateData sourceHandler adding default format', 
function ( assert ) {
+       QUnit.test( 'TemplateData sourceHandler adding default format', 
function ( assert ) {
                var sourceHandler = new mw.TemplateData.SourceHandler(),
                        simpleTemplateDataNoFormat = '<templatedata>{\n' +
                                '       "params": {}\n' +
@@ -666,18 +643,13 @@
                                params: {}
                        };
 
-               QUnit.expect( 1 );
-
-               sourceHandler.buildModel( simpleTemplateDataNoFormat )
+               return sourceHandler.buildModel( simpleTemplateDataNoFormat )
                        .done( function ( model ) {
                                assert.deepEqual(
                                        model.outputTemplateData(),
                                        simpleTemplateDataDefaultFormat,
                                        'Final templatedata output'
                                );
-                       } )
-                       .always( function () {
-                               QUnit.start();
                        } );
        } );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/348133
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3a698207440d8085a502fa54da8bb5feddfa1dcb
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to