????//region async-control??????
//QUnit.asyncTest() QUnit??????????asyncTest????????????????????????????????QUnit.start()??????
QUnit.asyncTest( "asynchronous test: one second later!"?? function ( assert ) {
assert.expect( 1 );
setTimeout( function () {
assert.ok( true?? "Passed and ready to resume!" );
QUnit.start();
}?? 1000 );
} );
QUnit.asyncTest( "asynchronous test: video ready to play"?? function ( assert ) {
assert.expect( 1 );
var $video = $( "video" );
$video.on( "canplaythrough"?? function () {
assert.ok( true?? "video has loaded and is ready to play" );
QUnit.start();
} );
} );
//QUnit.start() Start running tests again after the testrunner was stopped
//QUnit.stop()  ?????????ж??????????QUnit.stop ??????test runner??? ??????QUnit.start()???????
QUnit.test( "a test"?? function ( assert ) {
assert.expect( 1 );
QUnit.stop();
setTimeout( function () {
assert.equal( "someExpectedValue"?? "someExpectedValue"?? "ok" );
QUnit.start();
}?? 150 );
} );
//endregion
????//region module QUnit.module()?????????в?????y????????飬???????????????QUnit.module()??
// ??????????????????????????????????????????????????????????в??????С?
//Example: Use the QUnit.module() function to group tests together:
QUnit.module( "group a" );
QUnit.test( "a basic test example"?? function ( assert ) {
assert.ok( true?? "this test is fine" );
} );
QUnit.test( "a basic test example 2"?? function ( assert ) {
assert.ok( true?? "this test is fine" );
} );
QUnit.module( "group b" );
QUnit.test( "a basic test example 3"?? function ( assert ) {
assert.ok( true?? "this test is fine" );
} );
QUnit.test( "a basic test example 4"?? function ( assert ) {
assert.ok( true?? "this test is fine" );
} );
//Example: A sample for using the setup and teardown callbacks
QUnit.module( "module A"?? {
setup : function () {
// prepare something for all following tests
}??
teardown : function () {
// clean up after each test
}
} );
//Example: Lifecycle properties are shared on respective test context ?????????1??????????????????????
QUnit.module( "Machine Maker"?? {
setup : function () {
}??
parts : [ "wheels"?? "motor"?? "chassis" ]
} );
QUnit.test( "makes a robot"?? function ( assert ) {
this.parts.push( "arduino" );
assert.equal( this.parts?? "robot" );
assert.deepEqual( this.parts?? [ "robot" ] );
} );
QUnit.test( "makes a car"?? function ( assert ) {
assert.equal( this.parts?? "car" );
assert.deepEqual( this.parts?? [ "car"?? "car" ] );
} );
//endregion
????//region callback
//begin  Register a callback to fire whenever the test suite begins.
QUnit.begin( function ( details ) {
console.log( "Test amount:"?? details.totalTests );
} );
//done  Register a callback to fire whenever the test suite ends.
QUnit.done( function ( details ) {
console.log( "Total: "?? details.total?? " Failed: "?? details.failed?? " Passed: "?? details.passed?? " Runtime: "?? details.runtime );
} );
//log  Register a callback to fire whenever an assertion completes.
QUnit.log( function ( details ) {
if ( details.result ) {
return;
}
var loc = details.module + ": " + details.name + ": "??
output = "FAILED: " + loc + ( details.message ? details.message + "?? " : "" );
if ( details.actual ) {
output += "expected: " + details.expected + "?? actual: " + details.actual;
}
if ( details.source ) {
output += "?? " + details.source;
}
console.log( output );
} );
//moduleStart  Register a callback to fire whenever a module begins.
QUnit.moduleStart( function ( details ) {
console.log( "Now running: "?? details.name );
} );
//moduleDone  Register a callback to fire whenever a module ends.
QUnit.moduleDone( function ( details ) {
console.log( "Finished running: "?? details.name?? "Failed/total: "?? details.failed?? details.total );
} );
//testStart Register a callback to fire whenever a test begins.
QUnit.testStart( function ( details ) {
console.log( "Now running: "?? details.module?? details.name );
} );
//testDone Register a callback to fire whenever a test ends.
QUnit.testDone( function ( details ) {
console.log( "Finished running: "?? details.module?? details.name?? "Failed/total: "?? details.failed?? details.total?? details.duration );
} );
//endregion