Running unit tests for typescript in VS

I found some examples of running unit tests for typescript. All of them are based on links to both ts and js file, for example

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

Unfortunately, when I try to reference the js file, I get the following error:

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

If there is no control test runner, it does not load the js file for the test, and the test fails.

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

+4
source share
2 answers

You can use Chutzpah for this.

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

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

It also allows you to load external .js files (for example, dependent libraries) from your .ts unit test file with its own special :

 /// <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.

+4
source

There is no reason to include a link to the JS file:

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

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

 /// <reference path="../Calc.ts" /> 
+1
source

Source: https://habr.com/ru/post/1484466/


All Articles