How to install source files in jasmine.json using jasmine 2

I found a Jasmine 2.4 page for testing node.js files , and even mentions installing spec and source in the spec / support / jasmine.json file. But neither the online examples nor the jasmine examples show anything about telling jasmine where to find the source files.

Therefore, I keep getting ReferenceErrors because it does not seem to read my source files. It should be noted that at the moment I just use this to teach some students how to test and use their single-player toy projects for practice. (Like a game in the Hangman CLI, something like this.) So there are no .exports modules yet, although some of their projects use require() to connect third-party modules. I used Karma until I realized that it was only for the JavaScript browser, and require does not work.

Edit: I just found this post that sets basically the same thing, but I don't want to use grunt just to make Jasmine read in the source file. It looks like it should be embedded, for example, as Karma asks where your source and special files are located.

Second edit: I didn’t need to specify here, but Emarco marked my question as a duplicate of the one I linked in my first edit above, although I very specifically explained why another post does not answer my question.

+6
source share
3 answers

FWIW I found that the list of source files in the helpers list works.

 { "spec_dir": "spec", "spec_files": [ "fooSpec.js", "barSpec.js" ], "helpers": [ "../src/foo.js", "../src/bar.js" ] } 
+2
source

Unfortunately, jasmine developers seem to rely on grunts or other tools to use jasmine. As you mentioned, the only way to make it work without grunts or karma is to use require.js.

Put the require.js file from here into your index.html.

Just ask for the source file you have in the corresponding spec.js file:

 //Be careful to choose the right path from the sight of your spec.js var helloworld = require('../src/helloworld'); //the actual filename without '.js' 

Then export the script to "helloworld.js" like this:

 exports.helloWorld = function(){ return "Hello world!"; }; 

This worked for me ... I hope this helps, did not find another solution.

0
source

In your spec/support/jasmine.json you need to have an object with the spec_dir and spec_files .

 { "spec_dir": "spec", "spec_files": [ "fooSpec.js", "barSpec.js" ] } 

jasmine will use spec_dir to prefix your spec_files elements and run tests. For fooSpec.js, when you run jasmine in BASE_DIR for your project, tests will run for BASE_DIR/spec/fooSpec.js and BASE_DIR/spec/barSpec.js

-one
source

All Articles