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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With