Question

I've found couple of examples of running unit tests for typescript. All of them are based on referencing both ts and js file like

/// <reference path="../Calc.ts" />
/// <reference path="../Calc.js" />

Unfortunately when I try to reference js file I am getting the following error:

Incorrect reference: referenced file: "../Calc.js" cannot be resolved.

If there is no reference test runner doesn't load js file under test and test fails to execute.

Any ideas? Ideally I want to run tests in VS test explorer or Resharper test session.

Was it helpful?

Solution

You can use Chutzpah for that

With Chutzpah you can run your tests from command line and integrate your tests with Visual Studio Test Explorer.

Chutzpah allows you decide if you want to run the tests from .ts files, .js files, .html files or from all of them.

It also allows you to load external .js files (e.g. dependent libraries) from your .ts unit test file, with its specific :

/// <chutzpah_reference path="lib/jquery-1.9.1.min.js" />
/// <reference path="src/YourFileToBeTested.ts" />

Your unit tests can be written in TypeScript.

You can install Chutzpah from Visual Studio/Tools/Extensions and updates.

OTHER TIPS

There is absolutely no reason to include a reference to a JS file :

/// <reference path="../Calc.js" />

The use for /// <reference is to provide the compiler with information about type info present in another file. It has no runtime implications, only compile time implications. And all the compile time implications (typeinfo, code generation) are taken into account when you did:

/// <reference path="../Calc.ts" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top