From 4d8364a999c860afc0a72a6bb2c952051937dc38 Mon Sep 17 00:00:00 2001 From: joakin Date: Tue, 22 Aug 2017 13:28:05 +0200 Subject: [PATCH] Hygiene: Use promises A/A+ everywhere Remove usages of deprecated methods like .done which make jquery promises fall back to non-standard behavior Additional changes: * Rename var promise to a more descriptive name in tests Bug: T173819 Change-Id: I7b041d0a7a8c42a8eac947295d265e898085c60a --- tests/node-qunit/gateway/mediawiki.test.js | 4 ++-- tests/node-qunit/gateway/rest.test.js | 4 ++-- tests/node-qunit/ui/renderer.test.js | 14 +++++++------- tests/node-qunit/wait.test.js | 6 ++++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/node-qunit/gateway/mediawiki.test.js b/tests/node-qunit/gateway/mediawiki.test.js index a7d619789..f60cb132f 100644 --- a/tests/node-qunit/gateway/mediawiki.test.js +++ b/tests/node-qunit/gateway/mediawiki.test.js @@ -176,7 +176,7 @@ QUnit.test( 'MediaWiki API gateway returns the correct data ', function ( assert }, gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS ); - return gateway.getPageSummary( 'Test Title' ).done( function ( result ) { + return gateway.getPageSummary( 'Test Title' ).then( function ( result ) { assert.deepEqual( result, MEDIAWIKI_API_RESPONSE_PREVIEW_MODEL ); } ); } ); @@ -213,7 +213,7 @@ QUnit.test( 'MediaWiki API gateway handles missing pages ', function ( assert ) }, gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS ); - return gateway.getPageSummary( 'Test Title' ).done( function ( result ) { + return gateway.getPageSummary( 'Test Title' ).then( function ( result ) { assert.deepEqual( result, model ); } ); } ); diff --git a/tests/node-qunit/gateway/rest.test.js b/tests/node-qunit/gateway/rest.test.js index 53ad73fb0..b2b1de03c 100644 --- a/tests/node-qunit/gateway/rest.test.js +++ b/tests/node-qunit/gateway/rest.test.js @@ -244,7 +244,7 @@ QUnit.test( 'RESTBase gateway does not treat a 404 as a failure', function ( ass api = this.sandbox.stub().returns( deferred.reject( { status: 404 } ).promise() ), gateway = createRESTBaseGateway( api, { THUMBNAIL_SIZE: 200 }, provideParsedExtract ); - return gateway.getPageSummary( 'Test Title' ).done( function () { + return gateway.getPageSummary( 'Test Title' ).then( function () { assert.ok( true ); } ); } ); @@ -255,7 +255,7 @@ QUnit.test( 'RESTBase gateway returns the correct data ', function ( assert ) { ), gateway = createRESTBaseGateway( api, DEFAULT_CONSTANTS, provideParsedExtract ); - return gateway.getPageSummary( 'Test Title' ).done( function ( result ) { + return gateway.getPageSummary( 'Test Title' ).then( function ( result ) { assert.deepEqual( result, RESTBASE_RESPONSE_PREVIEW_MODEL ); } ); } ); diff --git a/tests/node-qunit/ui/renderer.test.js b/tests/node-qunit/ui/renderer.test.js index 990cfb4c6..cb1df9833 100644 --- a/tests/node-qunit/ui/renderer.test.js +++ b/tests/node-qunit/ui/renderer.test.js @@ -280,11 +280,11 @@ QUnit.test( 'show', function ( assert ) { behavior = createBehavior( this.sandbox ), token = 'some-token', $container = $( '
' ), - promise; + showPreview; preview.el.show = this.sandbox.stub(); - promise = renderer.show( + showPreview = renderer.show( preview, event, link, behavior, token, $container.get( 0 ) ); assert.notEqual( @@ -297,7 +297,7 @@ QUnit.test( 'show', function ( assert ) { 'Preview has been shown.' ); - return promise.done( function () { + return showPreview.then( function () { assert.ok( behavior.previewShow.calledWith( token ), 'previewShow has been called with the correct token.' @@ -313,7 +313,7 @@ QUnit.test( 'hide - fade out up', function ( assert ) { isTall: false }, $container = $( '
' ).append( preview.el ), - promise = renderer.hide( preview ); + hidePreview = renderer.hide( preview ); assert.ok( preview.el.hasClass( 'mwe-popups-fade-out-up' ), @@ -328,7 +328,7 @@ QUnit.test( 'hide - fade out up', function ( assert ) { '', 'Preview is still in the container.' ); - return promise.done( function () { + return hidePreview.then( function () { assert.equal( $container.html(), '', @@ -345,7 +345,7 @@ QUnit.test( 'hide - fade out down', function ( assert ) { isTall: false }, $container = $( '
' ).append( preview.el ), - promise = renderer.hide( preview ); + hidePreview = renderer.hide( preview ); assert.ok( preview.el.hasClass( 'mwe-popups-fade-out-down' ), @@ -360,7 +360,7 @@ QUnit.test( 'hide - fade out down', function ( assert ) { '', 'Preview is still in the container.' ); - return promise.done( function () { + return hidePreview.then( function () { assert.equal( $container.html(), '', diff --git a/tests/node-qunit/wait.test.js b/tests/node-qunit/wait.test.js index 318820b35..6a5a874a6 100644 --- a/tests/node-qunit/wait.test.js +++ b/tests/node-qunit/wait.test.js @@ -11,13 +11,15 @@ QUnit.test( 'it should resolve after waiting', function ( assert ) { callback(); } ); - return wait( 150 ).done( function () { + return wait( 150 ).then( function () { assert.strictEqual( timeout.getCall( 0 ).args[ 1 ], 150, 'It waits for the given duration' ); - } ).always( function () { timeout.restore(); + } ).catch( function ( err ) { + timeout.restore(); + throw err; } ); } );