Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" }
    ]
}
like image 281
Sayan Pal Avatar asked Jul 31 '15 06:07

Sayan Pal


People also ask

How do I add a test to test Explorer Visual Studio?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.

How do I enable test in Visual Studio?

Start, pause, and stop. To enable Live Unit Testing, select Test > Live Unit Testing > Start from the top-level Visual Studio menu.


1 Answers

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"] }
  ]
}
like image 170
Matthew Manela Avatar answered Oct 11 '22 12:10

Matthew Manela