-1

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" ]
    }
  ]
}
MyDaftQuestions
  • 4,487
  • 17
  • 63
  • 120

1 Answers1

3

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.

Vassilis Barzokas
  • 3,105
  • 2
  • 26
  • 41
  • Your answer looks excellent, when I changed from IE to Chrome, it showed that the error message about the lambda was likely a red herring. The issue is, helper is not defined - although it doesn't make sense, because it means IE was able to detect the Javascrrpt file and parse the script, but, the error message of `helpers is not defined` suggests it can't find the file - I updated my post – MyDaftQuestions Feb 19 '21 at 19:33
  • The `chutzpah.json` file is absolutely optional, you should be able to run the tests without it. However if you want to use it, it must reside in the root of your project. If you already have it there, then it looks like the `references` part is pointing to an invalid directory, since it instructs to look two folders above the current one. Also when you define the `references` property inside that json file, you no longer have to define the `// – Vassilis Barzokas Feb 21 '21 at 17:49
  • Turned out I was getting confused between what Jasmine and Chutzpah were doing.. Now, if only I could get Chutzpah to play nicely with prototype in javascript... https://stackoverflow.com/questions/66301835/chutzpah-does-not-let-me-run-tests-which-use-prototype – MyDaftQuestions Feb 21 '21 at 18:13