QUnit是一个前端测试工具。
判断效果:
html基本结构:
<h1 id="qunit-header">QUnit</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test</div>
js基本结构:
QUnit.test( "a basic test example"/*name*/, function( assert ) {
var value = "hello";
assert.equal( value, "hello", "We expect value to be hello"/*pass message*/ );
});
判断方法:测试就是要对目标进行判断,qunit中的判断方法主要有:
- ok(boolean,"info");
QUnit.test( "ok test", function( assert ) { assert.ok( true, "true succeeds" ); });
- equal(param1,param2,"info"); "=="
QUnit.test("equal test", function(assert) {
assert.equal( "", "", "Empty, Empty; equal succeeds" ); }); - strictEqual(param1,param2,"info");“===”
QUnit.test("deepEqual test", function(assert) { assert.deepEqual( {}, {}, "Empty object,Empty object; deepEqual succeeds"); //fail });
- deepEqual(param1,param2,"info");"===" 但是对对象类型不需要同一引用判断;
QUnit.test("deepEqual test", function(assert) { assert.deepEqual( {}, {}, "Empty object,Empty object; deepEqual succeeds"); //pass });
- 其它相反的方法:notEqual, notDeepEqual, notStrictEqual;