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