2015-12-05 75 views
0

當要測試的類位於模塊定義內時,我無法弄清楚如何在TypeScript中編寫Jasmine測試。這種設置工作正常:當被測試的類在模塊定義內時,TypeScript + Jasmine

Calculator.ts:

export class Calculator { 
    add(x: number, y: number): number { 
     return x + y; 
    } 
} 

CalculatorTest.ts:

///<reference path="scripts/typings/jasmine/jasmine.d.ts"/> 
///<reference path="../NancyApplication506/app/Calculator.ts"/> 
import Calculator = require("../NancyApplication506/app/Calculator"); 

describe("Calculator tests",() => { 
    var calculator: Calculator.Calculator; 

    beforeEach(() => { 
     calculator = new Calculator.Calculator(); 
    }); 
    it("should be able to add",() => { 
     expect(calculator.add(21,21)).toBe(42); 
    }); 
}); 

當我改變這樣Calculator.ts,不過,我一直無法弄清楚如何寫我的測試。

module SomeModuleName { 
    export class Calculator { 
     add(x: number, y: number): number { 
      return x + y; 
     } 
    } 
} 

我已經嘗試了幾十種不同的東西,都導致完全失敗。請請幫忙!

回答

0

在同一目錄下添加Chutzpah.json文件作爲測試:

{ 
    "Compile": { 
     "Mode": "External", 
     "Extensions": [ ".ts" ], 
     "ExtensionsWithNoOutput": [ ".d.ts" ], 
     "SourceDirectory": "../", 
     "OutDirectory": "../" 
    } 
} 

而只是刪除:

import Calculator = require("../NancyApplication506/app/Calculator"); 
相關問題