QUnit is a powerful, easy-to-use JavaScript unit test suite. Currently, it is not possible to directly use QUnit to test the javascript components in a Metro style apps written using Html/Javascript.

 

I have uploaded a project template on Visual Studio Gallery to enable QUnit Tests on Metro style apps built  using Html/Javascript. You can download it here. After installing this project template (and restarting Visual Studio), you can choose New Project -> Javascript -> QUnit Test for Metro Style Apps. You can hit F5 now to run the sample tests and see the results.

 

Metro style apps run in an an app container that restricts the capabilities of application. This is intended to protect the user from malicious apps. In order to run QUnit Tests inside the app container, I have made one change in qunit.js (added a window.toStaticHtml around the banner innerHtml). In addition, please note that I have added two capabilities in the appxmanifest [for Internet(client) and Document Library access]. These capabilities are used in my sample Metro style tests.

 

The sample tests are defined in the file tests.js in the js folder. There are 5 sample tests already defined for your reference.

 

I built this project template by starting from a Blank App and adding the required qunit files.

  1. qunit.css in css folder
  2. qunit.js and tests.js in js folder
  3. default.html in the project root folder (content updated)