Page MenuHomePhabricator

Translate extension: Fix tests to not assume synchronous jQuery.Deferred
Closed, ResolvedPublic


Each QUnit test should either return a Promise to QUnit.test (which QUnit will automatically wait for and also report a test failure if the Promise is rejected), or manually use assert.async() where needed.


QUnit.test( 'example should pass', function ( assert ) {
  return something().then( function ( val ) {
    assert.equals( val, 'expected' );
  } );
} );

QUnit.test( 'example should fail', function ( assert ) {
  var done = assert.async();
  something().fail( function ( val ) {
    assert.equals( val, 'error message' );
  } ).always( done );
} );

See also MediaWiki core's QUnit tests of mediawiki.api for more examples.

This is in preparation for jQuery 3.0, where $.Deferred callbacks are processed asynchronously.

Failures can be seen at the pending core patch:


03:54:38 Chrome 55.0.2883 (Linux 0.0.0) ext.translate.special.pagemigration -- Source units FAILED
03:54:38 	Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.

Event Timeline

Krinkle updated the task description. (Show Details)

Ah, so what I did in wasn't exactly correct?

Indeed, sorry. I left a comment there with more details.

Change 340288 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
Fix qunit tests for async handling

Change 340288 merged by jenkins-bot:
Fix qunit tests for async handling