Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup jasmine for typescript project

I need some guidance of how to set up unit testing of TypeScript project with Jasmine.

Test spec file looks like this:

/// <reference path="../../../typings/tsd.d.ts" />
import {Mediator} from '../../../services/remoting/Mediator';

describe('Mediator', () =>
{
    let mediator: Mediator;

    beforeEach(() => 
    {
        mediator = new Mediator();
    });

    it('blah blah', () =>
    {
        expect(mediator.TEST).toBeDefined();
    });
});

I use npm jasmine module to run tests. jasmine.json is pointing to the built JS spec files like this:

{
  "spec_dir": "build/spec",
  "spec_files": [
    "**/*.js"
  ]
}

The build spec file looks like this:

/// <reference path="../../../typings/tsd.d.ts" />
define(["require", "exports", '../../../services/remoting/Mediator'], function (require, exports, Mediator_1) {
    describe('factory: Mediator', function () {
        var mediator;
        beforeEach(function () {
            mediator = new Mediator_1.Mediator();
        });
        it('should have defined all required fields', function () {
            expect(mediator.ExecuteQuery).toBeDefined();
        });
    });
});
//# sourceMappingURL=Mediator.spec.js.map

when I try to run tests jasmine complains over undefined 'define' function:

ReferenceError: define is not defined

I have tried to search on the TypeScript + Jasmine but there is not much information (and I do not want to use full VisualStudio). So I would appreciate if someone can point me in the right direction of how to set typescript + jasmine and where my mistake is.

Thanks in advance.

like image 923
Amid Avatar asked May 13 '15 11:05

Amid


1 Answers

It looks like you are compiling using the --module amd flag, which is designed for asynchronous modules (like when you use RequireJS).

If you are running on Node, you need to supply --module commonjs. This will result in the following output:

var mediator_1 = require('../../../services/remoting/Mediator');

(Although the name of the variable may change as it creates a name on the fly for you when compiling ES6 style imports down).

like image 60
Fenton Avatar answered Sep 20 '22 13:09

Fenton