Daniel
Daniel

Reputation: 2531

jasmine not loading helper files

I'm trying to run jasmine helpers script but they are not being picked up. I was looking at the jasmine API and its looks straightforward, only add helpers to jasmine.json.

This is one of the helpers I was testing. It only purpose is to create a file when jasmine is invoked.

helpers/fileHelper.js

var fs = require('fs');

fs.writeFile("./jasmineHelperOutput.txt", "Hey there!", function(err) {

    if(err) {
        return console.log(err);
    }

}); 

jasmine.json

{
    "spec_dir": "./spec",
    "spec_files": [
        "**/*.spec.js"
    ],
    "helpers": [
        "helpers/**/*.js"
    ]
}

setup:

But it doesn't work.

What am I missing ?

I have created a simple jasmine project at https://github.com/dannyhuly/jasmine-with-helpers with the issue at hand.

Thanks.

Upvotes: 1

Views: 1416

Answers (2)

Danny Fenstermaker
Danny Fenstermaker

Reputation: 934

For those having this issue I spent a while digging through the jasmine code only to find that the helpers file is searched for relative to the "spec_dir": "./spec" in the jasmine.json file. SO if you dont have your tests under the spec folder and need to change the spec directory, make sure you correct the helpers file path.

Upvotes: 7

mehta-rohan
mehta-rohan

Reputation: 1341

It took me a bit long to get this:

In your test.spec.js add

var helpers = require('../helpers/funcHelper.js');
var helperFS = require('../helpers/fileHelper.js'); 


describe('test' , function(){

    it("should run", function(){

        helpers.helper_func(); // use helper
        helperFS.writeHelper();
        expect(1).toBe(1);
    })
})

and in fileHelper.js :

var fs = require('fs');
var writeHelper = function() {
fs.writeFile("./jasmineHelperOutput.txt", "Hey there!", function(err) {
    if (err) {
        return console.log(err);
    }})
};
exports.writeHelper = writeHelper;

Also check this: jasmine-git resolve code

Upvotes: 0

Related Questions