QUnit Tutorial
QUnit Useful Resources
Selected Reading
- QUnit - Nested Modules
- QUnit - Callbacks
- QUnit - Expect Assertions
- QUnit - Async Call
- QUnit - Only Test
- QUnit - Skip Test
- QUnit - Execution Procedure
- QUnit - Using Assertions
- QUnit - API
- QUnit - Basic Usage
- QUnit - Environment Setup
- QUnit - Overview
- QUnit - Home
QUnit Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
QUnit - Using Assertions
QUnit - Using Assertions
所有这些说法都属于Asert类。
这一类别提供了一套用于书面测试的断言方法。 仅记录有不成功的断言。
Sr.No. | Methods & Description |
---|---|
1 | async() Instruct QUnit要等到同步行动。 |
2 | deepEqual() 对原始类型、阵列、物体、固定表达方式、日期和功能进行深厚的复读比较。 |
3 | equi() 一种非限制性的比较,大致相当于Junnit s的断言Equals。 |
4 | expect () 具体说明在试验中预计会有多少主张。 |
5 | notDeepEqual() 粗略的反省比较,涉及原始类型、阵列、物体、定期表述、日期和职能。 |
6 | notEqual() 一种非限制性的比较,检查不平等。 |
7 | notOk() A booleaneck, inverse of ok() and CommonJS s claim.ok(), and amount to Jannit s claimFalse(). 如果第一个论点是虚假的,则通过。 |
8 | notPropEqual() 严格比较物体自己的特性,检查不平等。 |
9 | notStrictEqual() 严格比较,检查不平等。 |
10 | ok() A booleaneck, 相当于JS的断言.ok()和Junnit s claimTrue()。 第一种论点是正确的。 |
11 | propEqual() 对物体本身特性的严格类型和价值比较。 |
12 | push() 报告一项习俗主张的结果。 |
13 | strictEqual() 严格的类型和价值比较。 |
14 | throws() 如果退约造成例外,则进行测试,并以选择性方式比较所投的错误。 |
举一个例子说明上述大多数方法。
<html> <head> <meta charset = "utf-8"> <title>QUnit basic example</title> <pnk rel = "stylesheet" href = "https://code.jquery.com/qunit/qunit-1.22.0.css"> <script src = "https://code.jquery.com/qunit/qunit-1.22.0.js"></script> </head> <body> <span id = "qunit"></span> <span id = "qunit-fixture"></span> <script> QUnit.test( "TestSuite", function( assert ) { //test data var str1 = "abc"; var str2 = "abc"; var str3 = null; var val1 = 5; var val2 = 6; var expectedArray = ["one", "two", "three"]; var resultArray = ["one", "two", "three"]; //Check that two objects are equal assert.equal(str1, str2, "Strings passed are equal."); //Check that two objects are not equal assert.notEqual(str1,str3, "Strings passed are not equal."); //Check that a condition is true assert.ok(val1 < val2, val1 + " is less than " + val2); //Check that a condition is false assert.notOk(val1 > val2, val2 + " is not less than " + val1); //Check whether two arrays are equal to each other. assert.deepEqual(expectedArray, resultArray ,"Arrays passed are equal."); //Check whether two arrays are equal to each other. assert.notDeepEqual(expectedArray, ["one", "two"], "Arrays passed are not equal."); }); </script> </body> </html>
Verify the Output
你应当看到以下结果:
Advertisements