//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()后发生的所有测试调用将被分到模块,直到调用其他其他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 在测试环境下共享各自的生命周期内的属性
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