6

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" }
    ]
}
John Weisz
  • 30,137
  • 13
  • 89
  • 132
Sayan Pal
  • 4,768
  • 5
  • 43
  • 82
  • For anyone coming here with absolutely correctly configured unit-tests that just won't appear on the Test Explorer panel: **run all tests, then restart Visual Studio**. It solved the issue for me. – John Weisz Dec 26 '16 at 16:12

1 Answers1

4

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"] }
  ]
}
Community
  • 1
  • 1
Matthew Manela
  • 16,572
  • 3
  • 64
  • 66
  • Hi Matthew, thanks for the reply. I have the exact same issue. Should this config file be created manually? What folder it should be kept? Seems like bit hidden functionality? – user1829319 Sep 15 '15 at 22:17
  • 1
    Please see the documentation and examples on the chutzpah github page (https://github.com/mmanela/chutzpah/wiki/Chutzpah.json-Settings-File) – Matthew Manela Sep 16 '15 at 14:28
  • Sorry for late response. [This one](https://github.com/mmanela/chutzpah/blob/master/Samples/RequireJS/CustomBaseUrl/QUnit/chutzpah.json) worked for me. Thanks for your help :) – Sayan Pal Nov 25 '15 at 16:12