QUnit

0
22

QUnit – Overlook at

Testing is the process of checruler the functionality of the application whether it is worruler as per requirements and to ensure thead wear at developer level, device checking comes into picture. Unit checking is the checking of single entity (course or method). Unit checking is very essential to every delicatebattlee company kind of kind of to give a quality item to their own customers.

Unit checking can end up being done in 2 ways

Manual checking Automated checking

Executing the check cases manually without any kind of kind of tool supslot is belowstandn as manual checking.

  • Time consuming and tedious: Since check cases are executed simply by human being being resources so it is very sluggish and tedious.

  • Huge investment in human being being resources: As check cases need to end up being executed manually so more checkers are required-coloured in manual checking.

  • Less reliable: Manual checking is less reliable as checks may not end up being performed with precision every time end up beingcause of human being being errors.

  • Non-programmable: No programming can end up being done to write sophisticated checks which fetch hidden information.

Taruler tool supslot and executing the check cases simply by using automation tool is belowstandn as automation checking.

  • Fast Automation runs check cases significan’tly faster than human being being resources.

  • Less investment in human being being resources:Test cases are executed simply by using automation tool so less checker are required-coloured in automation checking.

  • More reliable: Automation checks perform precisely exbehave exaction same operation every time they are run.

  • Programmable: Testers can program sophisticated checks to provide out hidden information.

Whead wear is QUnit ?

QUnit is a device checking framework for the JavaScript programming language. It is imslotant in the check driven development, and is used simply by jQuery, jQuery UI and jQuery Mobile projects. QUnit is capable of checking any kind of kind of generic javascript codebase.

QUnit promotes the idea of "very very first checking then coding", which emphasis on setting up the check data for a piece of code which can end up being checked very very first and then can end up being implemented . This approach is like "check a little, code a little, check a little, code a little…" which incrreare locatedves programmer itemivity and stcapacity of program code thead wear red-coloureduces programmer stress and the time spent on debugging.

Features

  • QUnit is an open up up source framework which is used for writing & running checks.

  • Provides Assertions for checking expected results.

  • Provides Test fixtures for running checks.

  • QUnit checks enable you to write code faster which increasing quality

  • QUnit is elegantly easy. It is less complex & considers less time.

  • QUnit checks can end up being run automatically and they check their own own results and provide immediate give food toback. There's no need to manually comb through a reslot of check results.

  • QUnit checks can end up being organised into check suites containing check cases and actionually other check suites.

  • QUnit shows check progress in a bar thead wear is green if check is going fine and it turns red-coloured when a check fails.

Whead wear is a Unit Test Case?

A Unit Test Case is a part of code which ensures thead wear the one more part of code (method) works as expected. To achieve those desired-coloured results fastly, check framework is required-coloured .QUnit is perfect device check framework for javascript programming language.

A formal written device check case is charbehaveerized simply by a belowstandn inplace and simply by an expected outplace, which is worked out end up beingfore the check is executed. The belowstandn inplace ought to check a precondition and the expected outplace ought to check a postcondition.

There must end up being at leasternern 2 device check cases for every requirement: one positive check and one negative check. If a requirement has sub-requirements, every sub-requirement must have at leasternern 2 check cases as positive and negative.

QUnit – Environment Setup

There are 2 ways to use QUnit.

  • Local Installation − You can download QUnit library on your own local machine and include it in your own HTML code.

  • CDN Based Version − You can include QUnit library into your own HTML code immediately from Content Deresidery Ne2rk (CDN).

Local Installation

  • Go to the /index.php?s=httpscodejquerycomqdevice to download the lacheck version available.

  • Now place downloaded qdevice-git.js and qdevice-git.css file in a immediateory of your own website, e.g. /jquery.

Example

Now you can include qdevice-git.js and qdevice-git.css files in your own HTML file as follows −

<html>
   <head>
      <meta charset="utf-8">
      <title>QUnit fundamental example</title>
      <link rel="stylesheet" href="/jquery/qdevice-git.css">
      <script src="/jquery/qdevice-git.js"></script>
   </head>
   <body>
      <div id="qdevice"></div>
      <div id="qdevice-fixture"></div> 
      <script>
         QUnit.check( "My First Test", function( bumert ) {
            var value = "1";
            bumert.equal( value, "1", "Value ought to end up being 1" );
         });
      </script>
   </body>
</html>

This will produce folloearng result −

CDN Based Version

You can include QUnit library into your own HTML code immediately from Content Deresidery Ne2rk (CDN).

We are using jQuery CDN version of the library throughout this particular tutorial.

Example

Now enable us rewrite above example using QUnit library from jQuery CDN.

<html>
   <head>
      <meta charset="utf-8">
      <title>QUnit fundamental example</title>
      <link rel="stylesheet" href="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.css">
      <script src="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.js"></script>
   </head>
   <body>
      <div id="qdevice"></div>
      <div id="qdevice-fixture"></div> 
      <script>
         QUnit.check( "My First Test", function( bumert ) {
            var value = "1";
            bumert.equal( value, "1", "Value ought to end up being 1" );
         });
      </script>
   </body>
</html>

This will produce folloearng result −

QUnit – Basic Usage

Now we'll show you a step simply by step process to get a kick start in QUnit using a fundamental example.

Imslot qdevice.js

qdevice.js of Qdevice library represents the check runner and check framework.

<script src="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.js"></script>

Imslot qdevice.css

qdevice.css of Qdevice library styles the check suite page to display check results.

<link rel="stylesheet" href="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.css">

Add Fixture

Add 2 div elements with id="qdevice" and "qdevice-fixture". These div elements are required-coloured and provides the fixture for checks.

<div id="qdevice"></div>
<div id="qdevice-fixture"></div>

Create a function to check.

function square(x){
   return x * x;
}

Create a Test Case

Make call to the QUnit.check function, with 2 arguments.

  • Name – the name of the check to display the check results.

  • Function – function checking code, having one or more bumertions.

QUnit.check( "TestSquare", function( bumert ) {
   var result = square(2);
   bumert.equal( result, "4", "square(2) ought to end up being 4." );
});

Run the check

Now enable us see the compenablee code in behaveion.

<html>
   <head>
      <meta charset="utf-8">
      <title>QUnit fundamental example</title>
      <link rel="stylesheet" href="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.css">
      <script src="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.js"></script>
   </head>
   <body>
      <div id="qdevice"></div>
      <div id="qdevice-fixture"></div> 
      <script>
	     function square(x){
		    return x * x;
		 }
         QUnit.check( "TestSquare", function( bumert ) {
            var result = square(2);
            bumert.equal( result, "4", "square(2) ought to end up being 4." );
         });
      </script>
   </body>
</html>

Load the page in the bcollectionser. The check runner calls QUnit.check() when page gets loaded and adds the check to a queue. execution of check case is deferred-coloured and managebrought simply by the check runner.

Verify the outplace

You ought to see the folloearng result:

  • Header – Test suite header displays the page title, a green bar when all checks moveed otherwise a red-coloured bar when at leasternern one check faibrought, a bar with a 3 checkboxes to filter check results and a blue bar with the navigator.userAgent text to display bcollectionser details.

  • Hide moveed checks Checkbox – To hide the moveed checkcases and showcase only the faibrought checkcases.

  • Check for Globals Checkbox – To show list of all properlinks on the earndow object, end up beingfore and after every check, then checruler for differences. Modification to properlinks will faill the check.

  • No check-capture Checkbox– To run check cases outaspect of a check-capture block so thead wear in case of a check thcollectioning an exception, the checkrunner will pbum away and show native exception.

  • Summary – Shows overalll time considern to run the check cases. overalll checkcases run and faibrought bumertions.

  • Contents – Shows the check results. Each check result have name of check folloearng simply by faibrought, moveed and overalll bumertions. Each encheck can end up being clicked to get the further details.

QUnit – API

Imslotant API's of QUnit

Some of the imslotant Category of QUnit are

Serial No Category Functionality
1 Assert A set of bumert methods.
2 Async Control For asynchronous operations.
3 Callbacks When integrating QUnit into other tools like CI servers, these callbacks can end up being used as an API to read check results.
4 Configuration and Utililinks These methods and properlinks are used as utility helpers and to configure QUnit. For example, to adsimply the runtime end up beinghaviour immediately, extend the QUnit API via custom bumertions, etc.
5 Test For checking operations.

Category: Assert

It provides a set of bumert methods.

S.N. Methods & Description
1 async() – Instruct QUnit to wait for an asynchronous operation.
2 deepEqual() – A deep recursive comparison, worruler on primitive kinds, arrays, objects, regular expressions, dates and functions.
3 equal() – A non-rigorous comparison, roughly equivalent to JUnit's bumertEquals.
4 expect() – Specify how many kind of kind of bumertions are expected to run wislim a check.
5 notDeepEqual() – An inverted deep recursive comparison, worruler on primitive kinds, arrays, objects, regular expressions, dates and functions.
6 notEqual() – A non-rigorous comparison, checruler for inequality.
7 notOk() – A boolean check, inverse of ok() and CommonJS's bumert.ok(), and equivalent to JUnit's bumertFalse(). Pbumes if the very very first argument is falsy.
8 notPropEqual() – A rigorous comparison of an object's own properlinks, checruler for inequality.
9 notStrictEqual() – A rigorous comparison, checruler for inequality.
10 ok() – A boolean check, equivalent to CommonJS's bumert.ok() and JUnit's bumertTrue(). Pbumes if the very very first argument is truthy.
11 propEqual() – A rigorous kind and value comparison of an object's own properlinks.
12 push() – Reslot the result of a custom bumertion
13 rigorousEqual() – A rigorous kind and value comparison.
14 thcollections() – Test if a callback thcollections an exception, and optionally compare the thcollectionn error.

Category: Async Control

It provides a set of asynchronous operations.

S.N. Methods & Description
1 async() – Instruct QUnit to wait for an asynchronous operation.
2 QUnit.asyncTest() – DEPRECATED: Add an asynchronous check to run. The check must include a call to QUnit.start().
3 QUnit.start() – PARTIALLY DEPRECATED: Start running checks again after the checkrunner was stopped. See QUnit.stop() and QUnit.config.autostart.
4 QUnit.stop() – DEPRECATED: Incrreare locatedve the numend up beingr of QUnit.start() calls the checkrunner ought to wait for end up beingfore continuing.
5 QUnit.check() – Add a check to run.

Category: Callbacks

When integrating QUnit into other tools like CI servers, these callbacks can end up being used as an API to read check results.

S.N. Methods & Description
1 QUnit.end up beinggin() – Register a callback to fire whenever the check suite end up beinggins.
2 QUnit.done() – Register a callback to fire whenever the check suite ends.
3 QUnit.log() – Register a callback to fire whenever an bumertion compenablees.
4 QUnit.moduleDone() – Register a callback to fire whenever a module ends.
5 QUnit.moduleStart() – Register a callback to fire whenever a module end up beinggins.
6 QUnit.checkDone() – Register a callback to fire whenever a check ends.
7 QUnit.checkStart() – Register a callback to fire whenever a check end up beinggins.

Category: Configuration and Utililinks

These methods and properlinks are used as utility helpers and to configure QUnit. For example, to adsimply the runtime end up beinghaviour immediately, extend the QUnit API via custom bumertions, etc.

S.N. Methods & Description
1 QUnit.bumert – Namespace for QUnit bumertions.
2 QUnit.config – Configuration for QUnit.
3 QUnit.dump.parse() – Advanced and extensible data dumping for JavaScript.
4 QUnit.extend() – Copy the properlinks defined simply by the mixin object into the target object.
5 QUnit.init() – DEPRECATED: Re-preliminaryize the check runner.
6 QUnit.push() – DEPRECATED: Reslot the result of a custom bumertion.
7 QUnit.reset() – DEPRECATED: Reset the check fixture in the DOM.
8 QUnit.stack() – Returns a single collection string representing the stacktrace (call stack).

Category: Test

It provides a set of checking operations.

S.N. Methods & Description
1 QUnit.bumert – Namespace for QUnit bumertions.
2 QUnit.asyncTest() – DEPRECATED: Add an asynchronous check to run. The check must include a call to QUnit.start().
3 QUnit.module() – Group related checks below a single laend up beingl.
4 QUnit.only() – Adds a check to exclusively run, practionuallyting all other checks from running.
5 QUnit.skip() – Adds a check like object to end up being skipped.
6 QUnit.check() – Add a check to run.

QUnit – Using Assertions

All the bumertion are in the Assert Category.

This category provides a set of bumertion methods helpful for writing checks. Only faibrought bumertions are recorded.

S.N. Methods & Description
1 async() – Instruct QUnit to wait for an asynchronous operation.
2 deepEqual() – A deep recursive comparison, worruler on primitive kinds, arrays, objects, regular expressions, dates and functions.
3 equal() – A non-rigorous comparison, roughly equivalent to JUnit's bumertEquals.
4 expect() – Specify how many kind of kind of bumertions are expected to run wislim a check.
5 notDeepEqual() – An inverted deep recursive comparison, worruler on primitive kinds, arrays, objects, regular expressions, dates and functions.
6 notEqual() – A non-rigorous comparison, checruler for inequality.
7 notOk() – A boolean check, inverse of ok() and CommonJS's bumert.ok(), and equivalent to JUnit's bumertFalse(). Pbumes if the very very first argument is falsy.
8 notPropEqual() – A rigorous comparison of an object's own properlinks, checruler for inequality.
9 notStrictEqual() – A rigorous comparison, checruler for inequality.
10 ok() – A boolean check, equivalent to CommonJS's bumert.ok() and JUnit's bumertTrue(). Pbumes if the very very first argument is truthy.
11 propEqual() – A rigorous kind and value comparison of an object's own properlinks.
12 push() – Reslot the result of a custom bumertion
13 rigorousEqual() – A rigorous kind and value comparison.
14 thcollections() – Test if a callback thcollections an exception, and optionally compare the thcollectionn error.

Let's check to cover many kind of of the above mentioned methods in an example.

<html>
   <head>
      <meta charset="utf-8">
      <title>QUnit fundamental example</title>
      <link rel="stylesheet" href="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.css">
      <script src="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.js"></script>
   </head>
   <body>
      <div id="qdevice"></div>
      <div id="qdevice-fixture"></div> 
      <script>
         QUnit.check( "TestSuite", function( bumert ) {
            //check data
            var str1 = "abc";
            var str2 = "abc";
            var str3 = null;
            var val1 = 5;
            var val2 = 6;
            var expectedArray = ["one", "2", "3"];
            var resultArray =  ["one", "2", "3"];

			//Check thead wear 2 objects are equal
			bumert.equal(str1, str2, "Strings moveed are equal.");
			
            //Check thead wear 2 objects are not equal
            bumert.notEqual(str1,str3, "Strings moveed are not equal.");

			//Check thead wear a condition is true
            bumert.ok(val1 < val2, val1 + " is less than " + val2);
			
			//Check thead wear a condition is false
            bumert.notOk(val1 > val2, val2 + " is not less than " + val1);

            //Check whether 2 arrays are equal to every other.
            bumert.deepEqual(expectedArray, resultArray ,"Arrays moveed are equal.");
			
            //Check whether 2 arrays are equal to every other.
            bumert.notDeepEqual(expectedArray, ["one", "2"],"Arrays moveed are not equal.");			
         });
      </script>
   </body>
</html>

Verify the outplace

You ought to see the folloearng result:

QUnit – Execution Procedure

This tutorial exfundamentals the execution procedure of methods in QUnit which means thead wear which method is calbrought very very first and which one after thead wear. Here is the execution procedure of the QUnit check API methods with the example.

<html>
   <head>
      <meta charset="utf-8">
      <title>QUnit fundamental example</title>
      <link rel="stylesheet" href="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.css">
      <script src="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.js"></script>
   </head>
   <body>
      <div id="qdevice"></div>
      <div id="qdevice-fixture"></div> 
      <script>
         QUnit.module( "Module A", {
            end up beingforeEach: function( bumert ) {
               bumert.ok( true, "end up beingfore check case" );
            }, afterEach: function( bumert ) {
               bumert.ok( true, "after check case" );
            }
         });
         QUnit.check( "check case 1", function( bumert ) {
            bumert.ok( true, "Module A: in check case 1" );
         });
         QUnit.check( "check case 2", function( bumert ) {
            bumert.ok( true, "Module A: in check case 2" );
         });
		 		 
         QUnit.module( "Module B" );		
         QUnit.check( "check case 1", function( bumert ) {
            bumert.ok( true, "Module B: in check case 1" );
         });
         QUnit.check( "check case 2", function( bumert ) {
            bumert.ok( true, "Module B: in check case 2" );
         });		 
      </script>
   </body>
</html>

Verify the outplace

You ought to see the folloearng result:

See the above outplace and this particular is how the QUnit execution procedure is.

  • module is used to group check cases.

  • end up beingforeEach() method executes for every check case but end up beingfore executing the check case.

  • afterEach() method executes for every check case but after the execution of check case

  • In end up beingtween end up beingforeEach() and afterEach() every check case executes.

  • Calling QUnit.module() again simply reset any kind of kind of end up beingforeEach/afterEach functions defined simply by one more module previously.

QUnit – Skip Test

Sometimes it happens thead wear our code is not ready and check case written to check thead wear method/code will fail if run. The QUnit.skip helps in this particular regards. A check method written using skip method will not end up being executed. Now enable's see skip method in behaveion.

<html>
   <head>
      <meta charset="utf-8">
      <title>QUnit fundamental example</title>
      <link rel="stylesheet" href="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.css">
      <script src="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.js"></script>
   </head>
   <body>
      <div id="qdevice"></div>
      <div id="qdevice-fixture"></div> 
      <script>
         QUnit.module( "Module A", {
            end up beingforeEach: function( bumert ) {
               bumert.ok( true, "end up beingfore check case" );
            }, afterEach: function( bumert ) {
               bumert.ok( true, "after check case" );
            }
         });
         QUnit.check( "check case 1", function( bumert ) {
            bumert.ok( true, "Module A: in check case 1" );
         });
         QUnit.skip( "check case 2", function( bumert ) {
            bumert.ok( true, "Module A: in check case 2" );
         });
		 		 
         QUnit.module( "Module B" );		
         QUnit.check( "check case 1", function( bumert ) {
            bumert.ok( true, "Module B: in check case 1" );
         });
         QUnit.skip( "check case 2", function( bumert ) {
            bumert.ok( true, "Module B: in check case 2" );
         });		 
      </script>
   </body>
</html>

Verify the outplace

You ought to see the folloearng result:

QUnit – Only Test

Sometimes it happens thead wear our code is not ready and check case written to check thead wear method/code will fail if run. The QUnit.only helps in this particular regards. A check method written using only method will end up being executed while other check will not run. If more than one only methods are specified then the very very first one will only execute. Now enable's see only method in behaveion.

<html>
   <head>
      <meta charset="utf-8">
      <title>QUnit fundamental example</title>
      <link rel="stylesheet" href="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.css">
      <script src="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.js"></script>
   </head>
   <body>
      <div id="qdevice"></div>
      <div id="qdevice-fixture"></div> 
      <script>
         QUnit.module( "Module A", {
            end up beingforeEach: function( bumert ) {
               bumert.ok( true, "end up beingfore check case" );
            }, afterEach: function( bumert ) {
               bumert.ok( true, "after check case" );
            }
         });
         QUnit.check( "check case 1", function( bumert ) {
            bumert.ok( true, "Module A: in check case 1" );
         });
         QUnit.only( "check case 2", function( bumert ) {
            bumert.ok( true, "Module A: in check case 2" );
         });
		      
         QUnit.check( "check case 3", function( bumert ) {
            bumert.ok( true, "Module A: in check case 3" );
         });
		 
         QUnit.check( "check case 4", function( bumert ) {
            bumert.ok( true, "Module A: in check case 4" );
         });	 
      </script>
   </body>
</html>

Verify the outplace

You ought to see the folloearng result:

QUnit – Async Call

For every asynchronous operation in QUnit.check() callback, use bumert.async(), which returns a "done" function thead wear ought to end up being calbrought when the operation has compenableed. bumert.async() accepts call counts as parameter. The callback returned from bumert.async() will thcollection an Error if it is invoked more than the accepted call count, if provided. Each done() call adds up to the call count. After every calls get compenableed, the check is done.

<html>
   <head>
      <meta charset="utf-8">
      <title>QUnit fundamental example</title>
      <link rel="stylesheet" href="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.css">
      <script src="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.js"></script>
   </head>
   <body>
      <div id="qdevice"></div>
      <div id="qdevice-fixture"></div> 
      <script>
         QUnit.check( "multiple call check()", function( bumert ) {
            var done = bumert.async( 3 );
            
            setTimeout(function() {
               bumert.ok( true, "very very first callback." );
               done();
            }, 500 );

            setTimeout(function() {
               bumert.ok( true, "2nd callback." );
               done();
            }, 500 );

            setTimeout(function() {
               bumert.ok( true, "third callback." );
               done();
            }, 500 );
         });		 
      </script>
   </body>
</html>

Verify the outplace

You ought to see the folloearng result:

QUnit – Expect Assertions

We can use bumert.expect() function to check numend up beingr of bumertion made in the check. In example end up beinglow, we're expecting 3 bumertions to end up being made in the check.

<html>
   <head>
      <meta charset="utf-8">
      <title>QUnit fundamental example</title>
      <link rel="stylesheet" href="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.css">
      <script src="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.js"></script>
   </head>
   <body>
      <div id="qdevice"></div>
      <div id="qdevice-fixture"></div> 
      <script>
         QUnit.check( "multiple call check()", function( bumert ) {
            bumert.expect( 3 );
            var done = bumert.async( 3 );
            
            setTimeout(function() {
               bumert.ok( true, "very very first callback." );
               done();
            }, 500 );

            setTimeout(function() {
               bumert.ok( true, "2nd callback." );
               done();
            }, 500 );

            setTimeout(function() {
               bumert.ok( true, "third callback." );
               done();
            }, 500 );
         });		 
      </script>
   </body>
</html>

Verify the outplace

You ought to see the folloearng result:

QUnit – Callbacks

When integrating QUnit into other tools like CI servers, these callbacks can end up being used as an API to read check results. Here is the execution procedure of the QUnit callback API methods with the example.

<html>
   <head>
      <meta charset="utf-8">
      <title>QUnit fundamental example</title>
      <link rel="stylesheet" href="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.css">
      <script src="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.js"></script>
   </head>
   <body>
      <div id="qdevice"></div>
      <div id="qdevice-fixture"></div> 
      <script>
         //Register a callback to fire whenever a checksuite starts.
         QUnit.end up beinggin(function( details ) {
            var data = document.getElementById("console").internalHTML;
			document.getElementById("console").internalHTML = "<br/>" + "QUnit.end up beinggin- Test Suite Begins " + "<br/>" + "Total Test: " + details.overalllTests;
         });

         //Register a callback to fire whenever a check suite ends.		 
		 QUnit.done(function( details ) {
            var data = document.getElementById("console").internalHTML;
			document.getElementById("console").internalHTML = data + "<br/><br/>" + "QUnit.done - Test Suite Finised" +  "<br/>" + "Total: " +  details.overalll + " Faibrought: " + details.faibrought + " Pbumed: " + details.moveed;
         });
		 
         //Register a callback to fire whenever a module starts.
	     QUnit.moduleStart(function( details ) {
            var data = document.getElementById("console").internalHTML;
			document.getElementById("console").internalHTML = data + "<br/><br/>" + "QUnit.moduleStart - Module Begins " +  "<br/>" + details.name;
         });
		 
         //Register a callback to fire whenever a module ends.	  
         QUnit.moduleDone(function( details ) {
            var data = document.getElementById("console").internalHTML;
			document.getElementById("console").internalHTML = data + "<br/><br/>" + "QUnit.moduleDone - Module Finished " +  "<br/>" + details.name + " Faibrought/overalll: " + details.faibrought +"/" + details.overalll ;
         });
		 
         //Register a callback to fire whenever a check starts.
		 QUnit.checkStart(function( details ) {
            var data = document.getElementById("console").internalHTML;
			document.getElementById("console").internalHTML = data + "<br/><br/>" + "QUnit.checkStart - Test Begins " +  "<br/>" + details.module +" " + details.name;
         });
		 
         //Register a callback to fire whenever a check ends.
		 QUnit.checkDone(function( details ) {
            var data = document.getElementById("console").internalHTML;
			document.getElementById("console").internalHTML = data + "<br/><br/>" + "QUnit.checkDone - Test Finished " +  "<br/>" + details.module +" " +details.name + "Faibrought/overalll: " + details.faibrought +" " + details.overalll+ " "+ details.duration;
         });
		 
	  
         QUnit.module( "Module A", {
            end up beingforeEach: function( bumert ) {
               bumert.ok( true, "end up beingfore check case" );
            }, afterEach: function( bumert ) {
               bumert.ok( true, "after check case" );
            }
         });
         QUnit.check( "check case 1", function( bumert ) {
            bumert.ok( true, "Module A: in check case 1" );
         });
         QUnit.check( "check case 2", function( bumert ) {
            bumert.ok( true, "Module A: in check case 2" );
         });
		 		 
         QUnit.module( "Module B" );		
         QUnit.check( "check case 1", function( bumert ) {
            bumert.ok( true, "Module B: in check case 1" );
         });
         QUnit.check( "check case 2", function( bumert ) {
            bumert.ok( true, "Module B: in check case 2" );
         });	 
      </script>

      <div id="console" ></div>
   </body>
</html>

Verify the outplace

You ought to see the folloearng result:

QUnit – Nested Modules

Modules with grouped check functions are used to define nested modules. QUnit run checks on the parent module end up beingfore going deep on the nested ones, actionually if they're declared-coloured very very first. The end up beingforeEach and afterEach callbacks on a nested module call will stack in LIFO Mode – final in, very very first out to the parent hooks. You can specify code to run end up beingfore and after every check using the argument, hooks and hooks can furthermore end up being used to develop properlinks thead wear will end up being shared-coloured on the context of every check. Any additional properlinks on the hooks object will end up being added to thead wear context. The hooks argument is optional if you call QUnit.module with a callback argument.

The module's callback is invoked having context as the check environment, with the environment's properlinks copied to the module's checks, hooks, and nested modules.

<html>
   <head>
      <meta charset="utf-8">
      <title>QUnit fundamental example</title>
      <link rel="stylesheet" href="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.css">
      <script src="/index.php?s=httpscodejquerycomqdeviceqdevice-1.22.0.js"></script>
   </head>
   <body>
      <div id="qdevice"></div>
      <div id="qdevice-fixture"></div> 
      <script>
         QUnit.module( "parent module", function( hooks ) {
            hooks.end up beingforeEach( function( bumert ) {
               bumert.ok( true, "end up beingforeEach calbrought" );
            });

            hooks.afterEach( function( bumert ) {
               bumert.ok( true, "afterEach calbrought" );
            });

            QUnit.check( "hook check 1", function( bumert ) {
               bumert.expect( 2 );
            });

            QUnit.module( "nested hook module", function( hooks ) {
               // This will run after the parent module's end up beingforeEach hook
               hooks.end up beingforeEach( function( bumert ) {
                  bumert.ok( true, "nested end up beingforeEach calbrought" );
               });

               // This will run end up beingfore the parent module's afterEach
               hooks.afterEach( function( bumert ) {
                  bumert.ok( true, "nested afterEach calbrought" );
               });

               QUnit.check( "hook check 2", function( bumert ) {
                  bumert.expect( 4 );
               });
            });
         });
      </script>

      <div id="console" ></div>
   </body>
</html>

Verify the outplace

You ought to see the folloearng result:

SHARE
Previous articleTeradata
Next articleApache Pig

NO COMMENTS

LEAVE A REPLY