Search code examples
jasminejasmine-node

How to connect a function declaration between Node and Jasmine files?


In my pigLatin Jasmine file I am trying to get the following code to work:

var pigLatin = require("./pigLatin.js");

describe('#translate', function() {
    it('translates a word beginning with a vowel', function() {
    s = translate("apple");
    expect(pigLatin.s).toEqual('appleay');
    });
});

Here is my Node file:

function translate(argument) {
    return "appleay";
}


module.exports = {
    translate
}

I think this has something to do with the spy feature but I am having a bit of trouble wrapping my head around what it does exactly. Thank you for any help in advance.


Solution

  • Thanks to Brad I was able to figure this out. Here is the fixed solution:

    var pigLatin = require("./pigLatin.js");
    
    describe('#translate', function() {
    it('translates a word beginning with a vowel', function() {
        s = pigLatin.translate("apple");
        expect(s).toEqual('appleay');
    });