2016-07-29 78 views
0

我對Churtzpah和Jasmine非常陌生。我一直在嘗試使用Chutzpah進行測試。我使用Jasmine,Typescript,Chutzpah,angular2編寫單元測試。 每當我嘗試運行測試時,我都會看到我的測試正在被檢測到。 我chutzpah.json文件如下:找不到變量:require - Jasmine使用Chutzpah進行單元測試

 { 
    "Framework": "jasmine", 

    "Compile": { 
    "Mode": "Executable", 
    "Executable": "../compile.bat", 
    "Extensions": [ ".ts" ], 
    "ExtensionsWithNoOutput": [ ".d.ts" ], 
    "UseSourceMaps": true, 
    "Paths": [ 
     { 
     "SourcePath": "../", 
     "OutputPath": "../" 
     } 
    ] 
    }, 
    "References": [ 
    { "Path": "../node_modules/es6-shim/es6-shim.js" }, 
    { "Path": "../node_modules/reflect-metadata/Reflect.js" }, 
    { "Path": "../node_modules/systemjs/dist/system.src.js" }, 
    { "Path": "../node_modules/zone.js/dist/zone.js" }, 
    { "Path": "../node_modules/zone.js/dist/jasmine-patch.js" }, 
    { "Path": "../node_modules/zone.js/dist/async-test.js" }, 
    { "Path": "../node_modules/zone.js/dist/fake-async-test.js" }, 
    { "Path": "../node_modules/core-js/client/shim.min.js" }, 
    { 
     "Path": "app", 
     "Includes": [ "*.ts" ], 
     "Excludes": [ "*.d.ts" ] 
    } 
    ], 
    "Tests": [ 
    { "Include": "*.spec.ts" } 

    ] 
} 







import {it, describe, beforeEach, inject, beforeEachProviders} from "@angular/core/testing"; 

import {LoginService} from "./login.service"; 

describe("testing LoginService",() => { 
    let Myservice: LoginService = new LoginService(); 
    it("Should return true",() => { 
     expect(Myservice.validateUser("test", "test")).toBe(true); 
    }); 
     it("validateUser should fail if input values are null",() => { 
      expect(Myservice.validateUser(null, null)).toBe(false); 
     }); 
    }); 

讓我知道什麼,我需要做的。 感謝

中的compile.bat看起來像

@echo off tsc.cmd app/login/login.service.ts app/tests/login.service.spec.ts --sourcemap--declaration 

我看到測試輸出窗口中出現以下錯誤

Error: ReferenceError: Can't find variable: require 
at global code in file:"path" 
0 passed, 0 failed, 0 total (chutzpah). 

========== Total Tests: 0 passed, 0 failed, 0 total ========== 

回答

1

在放肆回購有可能是一個Angualr,打字稿樣本有用得到you started。下面是Chutzpah.json,但需要注意一些關鍵的事情。

  1. 確保測試不包括在參考部分
  2. 確保你明確地引用關鍵角框架在右側單獨文件

Chutzpah.json

{ 
    "Framework": "jasmine", 
    "Compile": { 
    "Mode": "Executable", 
    "Executable": "../compile.bat", 
    "Extensions": [ ".ts" ], 
    "ExtensionsWithNoOutput": [ ".d.ts" ], 
    "UseSourceMaps": true, 
    "Paths" : [ 
     { "SourcePath": "../", "OutputPath": "../" } 
    ] 
    }, 
    "References": [ 
    { "Path": "../../libs/angular.min.js", "IsTestFrameworkFile": true }, 
    { "Path": "../../libs/angular-mocks.js", "IsTestFrameworkFile": true }, 
    { "Path": "../src", "Includes": [ "*.ts" ], "Excludes": ["*.d.ts"] } 
    ], 
    "Tests": [{ "Include": "*Tests.ts" }] 
} 
+0

嘿@Matthew,感謝您的回覆。我修改了我的chutzpah.json ..請看看上面編輯過的chutpah.json文件。我知道如果我仍然需要做任何更改 –

1

它看起來就像您的來源路徑有錯誤。你指定:

"Path": "../app/" 

但是這個路徑是相對於chutzpah.json文件的位置。應該說:

"Path": "app" 
+0

我改變了它..這沒什麼幫助。但我不得不作出更正。謝謝 –

相關問題