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();

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


(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
 ReferenceError: helpers is not defined
 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 () {

and the javascript

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

2 thoughts on “Jasmine does not let me reference a function with <reference path”

  1. ES6 features are only partially implemented in IE 11, that is why you get those errors about Invalid character. Template literals $ that you refer to are not implemented. Check more about the compatibility here https://kangax.github.io/compat-table/es6/#ie11

    Depending on how you have set up your testing environment, you can change the browser that runs those tests to a different one, like Chrome or Firefox. For example if you use Karma as your test runner, you need to install the npm plugin karma-chrome-launcher and configure karma.conf.js so it uses Chrome.

    You haven’t given details about your testing environment, but it looks like you are still setting it up, so you could continue using Jasmine as your testing framework and additionally use Karma as your test runner and the free Visual Studio plugin Chutzpah Test Adapter, which enables you to run JavaScript unit tests from the command line and from inside of Visual Studio.

    This will require a bit of effort for setting it up from your side, however I there is a very detailed guide about how to integrate all these here.


Leave a Comment