项目准备启用Qunit, 先来尝试一下。 不说废话,上代码:
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>QUint</title> <link rel="stylesheet" href="qunit.css"> <script src="qunit.js"></script> <script type="text/javascript"> myfunc = function(a){ return a^3; } function Foo( x, y, z ) { this.x = x; this.y = y; this.z = z; } test("Simple", function(assert) { assert.ok(function(){return "world1"}, "world"); assert.notOk(1 === "1", "=== failed!"); ok(1 == "1", "== pass!"); equal('1',1,"1==1 equal"); assert.ok(myfunc(1) == 2,"calc pass"+(1^3)); }); var a = new Foo(1,2,3); var b = a; test("object",function(){ propEqual(a,b,"a is same as b"); strictEqual(a,b,"a is strict same as b"); a.x =8; propEqual(a,b,"a is same as b"); a = {x:8,y:2,z:3}; propEqual(a,b,"a is same as b"); notStrictEqual(a,b,"a is not strict same as b"); a = new Foo(1,2,3); notPropEqual(a,b,"a is not same as b"); b = new Foo(1,2,3); notEqual(a,b,"a is not same as b"); notStrictEqual(a,b,"a is not strict same as b for different object"); deepEqual(a,b,"a b DeepEqual"); }); test( "async", function( assert ) { assert.expect( 2 ); var done1 = assert.async(); var done2 = assert.async(); setTimeout(function() { assert.ok( true, "test resumed from async operation 1" ); done1(); }, 500 ); setTimeout(function() { assert.ok( true, "test resumed from async operation 2" ); done2(); }, 150); }); QUnit.test( "expect test", function( assert ) { assert.expect( 1 ); function calc( x, operation ) { return operation( x ); } var result = calc( 2, function( x ) { assert.ok( true, "calc() calls operation function" ); return x * x; }); assert.equal( result, 4, "2 squared equals 4" ); }); </script> </head> <body> <h1 id="qunit-header">QUnit Report</h1> <h2 id="qunit-banner"></h2> <ol id="qunit-tests"></ol> </body> </html>