Search code examples
node.jsvisual-studiojasminechutzpah

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


I am trying to use Jasmine, via NodeJs and Chutzpah 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 of my original post as it's no longer valuable)

I have even removed the <reference path> and replaced it with chutzpah.json at the root of the project with

{
  "Framework": "jasmine",
  "References": [
    {
      "Path": "../../net5.Ui/wwwroot/Shared/Javascript/",
      "Include": "*.js",
      "Exclude": "*app.js"
    }
  ],
  "Tests": [
    {
      "Path": "Tests/",
      "Includes": [ "*Spec.js" ]
    }
  ]
}

Solution

  • 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.