2

I use AngularJS with TypeScript in a Web application in Visual Studio 2013. I can run tests in JavaScript just fine, but the tests written in TypeScript are not run. In fact, the ReSharper Test Runner displays a "Test Not Run" status for every test written in TypeScript, and I have no idea why. When I read blogs about this topic, they describe exactly what I do.

My code for such a unit test is:

/// <reference path="../typings/jasmine/jasmine.d.ts" />
/// <reference path="../AngularApp/Models/Member.ts" />
/// <reference path="../AngularApp/Models/Contract.ts" />


describe("Member", () => {
    "use strict";

    var contracts = new Array<App.Controllers.Contract>();
    var sut = new App.Controllers.Member("Elvis", "Presley", "350108-11.2222",
        new Date("1935-01-08"), new Date("1977-08-16"), "M", "Home", "", "90210", "Graceland",
        contracts);

    it("must not be null", () => {
        expect(sut).not.toBeNull();
    });


    it("must contain zero Contracts", () => {
        expect(sut.contracts).not.toBeNull();
        expect(sut.contracts.length).toBe(0);
    });    
});

What can cause this problem?

3 Answers 3

1

You cannot directly run tests written in typescript, they need to be transpiled into js first. Since your using visual studio i suppose your ts files are compile on save, so you need to check test config file ( example Karma.conf.js) to see if it looking for tests in the right directory. If you want to debug your ts test file, your test runner in visual studio must support source-maps. Have a look at this test runner for Vs2013 : https://github.com/MortenHoustonLudvigsen/KarmaTestAdapter. It supports source-maps.

Sign up to request clarification or add additional context in comments.

1 Comment

I don't use Karma, I use Jasmine... And the ReSharper test runner finds the tests, it just doesn't run them. It displays a "Test not run" message for every TypeScript test...
0

You could try wrapping your test setup code in a beforeEach method:

/// <reference path="../typings/jasmine/jasmine.d.ts" />
/// <reference path="../AngularApp/Models/Member.ts" />
/// <reference path="../AngularApp/Models/Contract.ts" />


describe("Member", () => {
    "use strict";

    var contracts : any;
    var sut : any;

    beforeEach(() => {
        var contracts = new Array<App.Controllers.Contract>();
        var sut = new App.Controllers.Member("Elvis", "Presley", "350108-11.2222",
                  new Date("1935-01-08"), new Date("1977-08-16"), "M", "Home", "", "90210", "Graceland",
                  contracts);
    });

    it("must not be null", () => {
        expect(sut).not.toBeNull();
    });


    it("must contain zero Contracts", () => {
        expect(sut.contracts).not.toBeNull();
        expect(sut.contracts.length).toBe(0);
    });    
});

Comments

0

Jasmine is a framework for testing JavaScript. As such, it is incompatible with TypeScript. You can use TypeScript and test it, you have to transpile it first into JavaScript, using Grunt, Gulp or Webpack.

install Typescript package, and then you can use tsc in command line to turn all .ts files into .js files - then it should work.

I was stuck on the same problem :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.