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" }
]
}
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.
Start, pause, and stop. To enable Live Unit Testing, select Test > Live Unit Testing > Start from the top-level Visual Studio menu.
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"] }
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With