簡體   English   中英

如何為打字稿項目設置茉莉花

[英]How to setup jasmine for typescript project

我需要一些有關如何使用Jasmine設置TypeScript項目的單元測試的指導。

測試規范文件如下所示:

/// <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();
    });
});

我使用npm茉莉花模塊運行測試。 jasmine.json指向構建的JS規范文件,如下所示:

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

構建規范文件如下所示:

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

當我嘗試運行測試時,茉莉花抱怨未定義的“定義”功能:

ReferenceError: define is not defined

我試圖在TypeScript + Jasmine上進行搜索,但是沒有太多信息(並且我不想使用完整的VisualStudio)。 因此,如果有人能指出正確的方向設置打字稿+茉莉花以及我的錯誤所在,我將不勝感激。

提前致謝。

看起來您正在使用--module amd標志進行編譯,該標志是為異步模塊設計的(例如使用RequireJS時)。

如果您在Node上運行,則需要提供--module commonjs 這將導致以下輸出:

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

(盡管變量的名稱可能會更改,因為在向下編譯ES6樣式時會為您動態創建一個名稱)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM