Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set source files in jasmine.json with Jasmine 2

I've found Jasmine 2.4's page on testing node.js files, and it even mentions setting the spec and source files in the spec/support/jasmine.json file. But neither the online examples nor the jasmine examples show anything on how to tell jasmine where to find the source files.

So I keep getting ReferenceErrors because it doesn't seem to be reading in my source files. It should be noted that for now I'm just using this to teach some students about testing, and using their single-file toy projects for practice. (Like a CLI Hangman Game, that sort of thing.) So for now there's no module.exports going on, although some of their projects to use require() to bring in third-party modules. I was using Karma until I realized that's only supposed to be for browser JavaScript, and require kept failing.

Edit: I just found this post that is asking basically the same thing, but I don't want to use grunt just to make Jasmine read in a source file. Seems like something that should be built in, like how Karma asks for where your source and spec files are.

Second Edit: I shouldn't have to put this here, but Emarco marked my question as a duplicate of the one I linked in my first edit above, even though I very specifically explained why that other post doesn't answer my question.

like image 431
bobbyz Avatar asked May 17 '16 18:05

bobbyz


Video Answer


1 Answers

FWIW I've found that listing my source files in the helpers list works..

{
  "spec_dir": "spec",
  "spec_files": [
    "fooSpec.js",
    "barSpec.js"
  ],
  "helpers": [
    "../src/foo.js",
    "../src/bar.js"
  ]
}
like image 153
Paul Roberts Avatar answered Nov 15 '22 22:11

Paul Roberts