-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Adding promise handling on qunit callbacks
- Loading branch information
1 parent
a3b1463
commit 6711d27
Showing
7 changed files
with
156 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>QUnit Callbacks Test Suite</title> | ||
<link rel="stylesheet" href="../dist/qunit.css"> | ||
<script src="../dist/qunit.js"></script> | ||
<script src="callbacks-promises.js"></script> | ||
</head> | ||
<body> | ||
<div id="qunit"></div> | ||
<div id="qunit-fixture"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
var done = false; | ||
var callbackCalled = {}; | ||
|
||
function timeoutPromiseCallback( callback, timeout ) { | ||
return new Promise( function( resolve ) { | ||
setTimeout( function() { | ||
callback(); | ||
resolve(); | ||
}, timeout ); | ||
} ); | ||
} | ||
|
||
QUnit.begin( function() { | ||
return timeoutPromiseCallback( function() { | ||
callbackCalled.begin = true; | ||
}, 100 ); | ||
} ); | ||
QUnit.moduleStart( function() { | ||
return timeoutPromiseCallback( function() { | ||
callbackCalled.moduleStart = true; | ||
}, 100 ); | ||
} ); | ||
QUnit.testStart( function() { | ||
return timeoutPromiseCallback( function() { | ||
callbackCalled.testStart = true; | ||
}, 100 ); | ||
} ); | ||
|
||
QUnit.testDone( function() { | ||
return timeoutPromiseCallback( function() { | ||
callbackCalled.testStart = false; | ||
callbackCalled.testDone = true; | ||
}, 100 ); | ||
} ); | ||
QUnit.moduleDone( function() { | ||
return timeoutPromiseCallback( function() { | ||
callbackCalled.moduleStart = false; | ||
callbackCalled.moduleDone = true; | ||
}, 100 ); | ||
} ); | ||
QUnit.done( function() { | ||
return timeoutPromiseCallback( function() { | ||
callbackCalled.done = true; | ||
}, 100 ); | ||
} ); | ||
|
||
QUnit.done( function() { | ||
if ( done ) { | ||
return; | ||
} | ||
|
||
done = true; | ||
|
||
QUnit.test( "verify callback order", function( assert ) { | ||
assert.ok( callbackCalled.begin ); | ||
assert.notOk( callbackCalled.moduleStart ); | ||
assert.notOk( callbackCalled.testStart ); | ||
assert.ok( callbackCalled.testDone ); | ||
assert.ok( callbackCalled.moduleDone ); | ||
assert.ok( callbackCalled.done ); | ||
} ); | ||
} ); | ||
|
||
QUnit.module( "module1", function() { | ||
QUnit.test( "test1", function( assert ) { | ||
assert.ok( callbackCalled.begin ); | ||
assert.ok( callbackCalled.moduleStart ); | ||
assert.ok( callbackCalled.testStart ); | ||
} ); | ||
} ); |