Jasmine does not let me reference a function with <reference path

I am trying to use Jasmine, via NodeJs to test the javascript in my project. This is in Visual Studio

The Jasmine test looks like

/// <reference path ='../../net5.Ui/wwwroot/Shared/Javascript/helpers.js' />
    
describe('Helpers test', function () {
    it('Test contains', function () {
        const result = helpers.isMatch();
        expect(result).toBe(true);
    });
});

My javascript files all have a similar structure (a singleton approach)

const helpers = new function(){
    this.isMatch = function(){ return true; }
}

Visual Studio is able to detect the tests.

Node version 14.15.4

UPDATE

(I have stripped some context as it’s no longer valuable)

I ran from command line as requested in comments. It gives:

Test Suite 1 Test 1
 Message:
 ReferenceError: helpers is not defined
Stack:
 ReferenceError: helpers is not defined
    at UserContext.<anonymous> (H:\GitHub\path\nodejs.TestJs\Tests\UnitTest1Spec.js:7:24)
    at <Jasmine>
    at processImmediate (node:internal/timers:463:21)

Frustratingly, this website shows what I am trying to do and I don’t see how it is different to what I am doing

/// <reference path=""../application.js"">
describe("App", function () {
    describe("foo", function () {
        it("should return bar", function () {
            expect(App.foo()).toEqual("bar");
        });
    });
});</reference>

and the javascript

var App = {
    foo: function() {
        return "bar123";
    }
};

Leave a Comment