Search code examples
visual-studio-2015qunitchutzpah

QUnit TFS Integration


Recently I've been researching and attempting to implement a JavaScript testing suite.

Little bit of background. I work for an ECom business that uses .NET for it's websites, we then augment our sites with JavaScript (e.g. Animations, Smoother UX and Ajax calls)

So our useage of JavaScript is mainly to target dom elements and manipulate them based on an event, or we'll make an Ajax call to update something for example, receiving a response back in JSON.

This is all great, and I found QUnit to work pretty well with what we use JavaScript for. I've been using a html test runner file, basically allowing me to inject DOM elements in on the setup for the module, so I can have the DOM in the state I want it to be, so we can target elements.

Now comes the next part, I'm trying to integrate it in to Visual Studio 2015. I've downloaded the Chutzpah extension and have been adding in my JavaScript Unit Tests, WITH the HTML test runner.

My issue is that the Test Explorer is coming up with 2 sets of tests. It's picking up the tests from my test runner file, and the tests from the actual test file. The test runner ones will pass, but the test file doesn't, this is because it doesn't have a reference to what it's testing outside of the test runner file. Has anyone encountered this before? Or knows a way round this, or maybe i'm just trying to use Chutzpah incorrectly.

So here's my solution explorer (bare in mind some of this is there just to test a theory and get things working)

enter image description here

enter image description here


Solution

  • Chutzpah is designed to build the test runner HTML file for you based on the configuration in a chutzpah.json file, you can see some samples here. You set up the chutzpah.json to describe what you project looks like and then chutzpah can run directly on your test files. This is the most common way to configure chutzpah.

    However, if you just want chutzpah to run directly on your HTML file, it can do that to. Then you just need a chutzpah.json file to tell chutzpah to IGNORE running on your JS files.