2016-07-29 13 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 

のように見える私はあるかもしれないAngualr-活字体のサンプルがある大胆レポで

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

テスト出力ウィンドウに次のエラーが表示されますyou startedを入手すると便利です。下のChutzpah.jsonですが、注意すべき重要な事項がいくつかあります。

  1. あなたは明示的に右

に個別にキーの角フレームワークファイルを参照してくださいテストが参照セクション

  • に含まれていないことを確認し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

    私はそれを変更しました..それは役に立たない。しかし、私はその訂正をしなければなりませんでした。 –

    関連する問題