1

I can't get testing of TypeScript in VS using jasmine/Chutzpah to work with AMD.

Sample.ts:

export class Sample {
    constructor(public name: string) { }
}

Simple.ts:

/// <reference path="./require.d.ts" />
/// <reference path="./jasmine.d.ts" />

import SampleModule = module("./Sample");

describe("TypeScript1", function () {
    it("should pass a simple test", function () {
          expect(1).toEqual(1);
    });
});

describe("TypeScript2", function () {
    it("should pass a sample test", function () {
        var sample = new SampleModule.Sample("Wow");
            expect(sample.name).toEqual("Wow");
    });
});

...this results in:

Test Name: TypeScript1 should pass a simple test Test Outcome: Passed

Test Name: TypeScript2 should pass a sample test Test Outcome: Failed Test Duration: 0:00:00

Result Message: ReferenceError: Can't find variable: SampleModule in file:typescripthtmlapp1/_Chutzpah.28.simple.js (line 9)

Adding:

/// <reference path="./Sample.ts" />

...results in no detected tests.

What am I missing?

3 Answers3

3

I think that the problem is that the Javascript module loader (require.js) is not included by Chutzpah when running the test, and so the module does not load - hence the error.

See change request here - apparently the solution will be to add something like this in the test file:

///<chutzpah_reference path="../scripts/require.js" />

but the fix is not available yet.

UPDATE

The fix should be available in Chutzpah version 2.4.

MiMo
  • 11,793
  • 1
  • 33
  • 48
  • what you mean with "chutzpah_reference" ? I am getting same problem trying run Qunit Tests using chutzpah addin. see http://stackoverflow.com/questions/16464984/how-to-load-a-public-function-using-qunit-and-typescript – Rolando May 09 '13 at 22:08
  • The author of Chutzpath added the handling of a 'chutzpah_reference' tag to specify JavaScript files that need to be included when running the test - see the link referred by 'here' in my answer. – MiMo May 10 '13 at 08:34
  • @MiMo, I have installed Chutzpah 2.4 and added the /// – user2144887 May 10 '13 at 15:15
  • @user2144887: the ticket concerning that issue said that the fix was made, but not released at that time - did you check if the fix is supposed to be in 2.4? – MiMo May 11 '13 at 16:40
  • @user2144887: sorry, no idea - I did not try it (yet) myself, so I cannot even tell you for sure if it works. – MiMo May 13 '13 at 08:06
0

Chutzpah does not currently support TypeScript files which generate AMD code. I had experimented with this a couple releases ago but ran into issues with how TypeScript generated its output.

I plan to revisit this in a future release and I file this item to track the state of this work.

Could you visit that item and attach a zip of your sample so I can be sure that my fix correctly addresses your scenario.

Matthew Manela
  • 16,572
  • 3
  • 64
  • 66
0

Here you can find working sample with TypeScript - jasmine - Chutzpah - AMD - Visual Studio 2012: http://chrisseroka.wordpress.com/2014/02/23/javascripttypescript-unit-testing-11-sample-projects-for-resharper-chutzpah-and-karma/

frizik
  • 1,766
  • 1
  • 13
  • 17