Testing javascript with Chutzpah and requirejs

百般思念 提交于 2019-12-03 11:36:17
Adamy

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" }
    ]
}

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!