11

I just wonder if there is a simple tutorial showing how to test javascript in visual studio with Chutzpah, require.js and jasmine.

Basically, i want to run the tests without using an .html file so that i can see the results in the vs test explorer.

ppoliani
  • 4,792
  • 3
  • 34
  • 62

3 Answers3

9

You can find some sample codes here: https://chutzpah.codeplex.com/SourceControl/latest#Samples/RequireJS/Jasmine/tests/base/base.jasmine.test.js

Please note if you want to use requirejs with Chutzpah and Jasmine, you need to set TestHarnessReferenceMode to AMD in chutzpah.json. Otherwise the tests won't be ran in browser.

{
    "Framework": "jasmine",
    "TestHarnessReferenceMode": "AMD",
    "TestHarnessLocationMode": "SettingsFileAdjacent",
    "References": [
        { "Path": "require-2.1.8.js" },
        { "Path": "config.js" }
    ],
    "Tests": [
        { "Path": "tests" }
    ]
}
John Weisz
  • 30,137
  • 13
  • 89
  • 132
Adamy
  • 2,789
  • 3
  • 27
  • 25
1

Here's a pretty useful video to get you started with Chutzpah and Jasmine ...

http://www.youtube.com/watch?v=meJ94rAN7P8

I don't think if you add Require js it is going to make much difference to the demo in the video in terms of how you set things up.

Matthew Blott
  • 209
  • 3
  • 10
  • 1
    Unfortunately it does chutzpah waits for the page load to complete, however requirejs is probably still waiting to modules to download. the result is that Chutzpah doesn't see the tests and declared 0 tests are successful. – Mark Broadhurst May 01 '13 at 09:34
  • 1
    @SaintGerbil You need to set TestHarnessReferenceMode to AMD in chutzpah.json and follow the sample link I posted in my answer. – Adamy Apr 17 '14 at 04:33
0

I managed to make the tests run simply by adding an AMD module where i load all the test modules; That is, i created the all.test.js file in which i simply load all the test modules as dependencies:

requirejs.config({
    // same as the applications main baseUrl
    baseUrl: '../',
});

requirejs([
      'tests/moduleA',
      'tests/moduleB'
    ],
    function () { }
);

In a sense, this is the main requires module for the test modules.

Now you right click and open it in a browser or you can use the test runner to run the tests.

ppoliani
  • 4,792
  • 3
  • 34
  • 62