unit-testingtypescriptvisual-studio-2015qunitchutzpah

JS Unit Test not appearing in VS 2015 Test Explorer


I am new to JavaScript unit testing. I am trying to test typescript classes and my tests are also written in typescript, which somewhat looks like below:

/// <reference path="../../typings/qunit/qunit.d.ts" />
import Utility1 = require("../utility");//This is script I want to test.    

test("utility_test",function() {

    ...

    var result = ...;
    var expected = ...;
    equal(result, expected, "Test failed");
})

I am using VS 2015 with chutzpah test adapter installed as shown here. To be clear I have installed this to extension to vs 2015: Chutzpah Test Runner Context Menu Extension, and Chutzpah Test Adapter for the Test Explorer and also added Chutzpah NuGet package.

Yet when I build my project, the test doesn't appear in the Test Explorer. And when I tried to run the test from context menu, it fails with this error: Error: Error: Called start() outside of a test context while already started.

Can anyone please let me know where I am going wrong?


EDIT For the one looking for the solution with require.js, this here worked for me. Now my Chutzpah.json looks like below:

{
    "Framework": "qunit",
    "CodeCoverageExcludes": [ "*/require.config.js" ],
    "TestHarnessReferenceMode": "AMD",
    "TestHarnessLocationMode": "SettingsFileAdjacent",
    "TypeScriptModuleKind": "AMD",
    "AMDBaseUrl": "",
    "EnableTestFileBatching": true,
    "Compile": {
        "Mode": "External",
        "Extensions": [ ".ts" ],
        "ExtensionsWithNoOutput": [ ".d.ts" ]
    },
    "References": [
        { "Path": "require.js" },
        { "Path": "require.config.js" },
    ],
    "Tests": [
        { "Path": "jsTests" }
    ]
}

Solution

  • Chutzpah no longer bundles the Typescript compiler inside of it (as of version 4). You must tell Chutzpah where to find your generated .js files (or/and how to compile them if you want it to).

    See the documentation for the Compile setting as well as these code samples.

    Most people will use the external compile mode when working with Visual Studio since VS can compile the .ts files for you and you just need to tell Chutzpah where to find them. That will look like this:

    {
      "Compile": {
        "Mode": "External",
        "Extensions": [".ts"],
        "ExtensionsWithNoOutput": [".d.ts"]
       },
      "References": [
        {"Includes": ["*/src/*.ts"], "Excludes": ["*/src/*.d.ts"] }
      ],
      "Tests": [
        { "Includes": ["*/test/*.ts"], "Excludes": ["*/test/*.d.ts"] }
      ]
    }