dimanche 29 octobre 2017

Jasmine test on javascript from file in another directory

I am trying to write a unit test suite for a javascript file that is located elsewhere in the project directory.

I cannot relocate that file or the spec file due to certain other dependencies, how can I import it?

here's how the project directory structure looks:

  • ./
  • ./js
  • ./js/module
  • ./js/module/MYFUNC.js
  • ...
  • ./spec/MYFUNC_tests.js

MYFUNC.js looks like this:

var constants = {a:100}
var myObj = function(){
    var local_var = true;

    myObj.doSomething = function(){
        return true;
    }
    myObj.answerToEverything = function(){
        return 42;
    }
}

This is my goal test case in MYFUNC_tests.js

describe("MYFUNC ", function(){
    var obj_a = myObj();
    it("Universe question ", function(){
        expect(obj_a.answerToEverything).toBe(42);
        done();
    }
});

Any help or links to guides on correct importing would be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire