2016-08-16 2 views
0

ジャスミンでAngular 2アプリのテストを作成しようとしています。いくつかのチュートリアルに続いて、たくさん試しました。基本的なテストで動作しますが、コンポーネントのインスタンスを作成したり、モックしようとするとテストレスが得られません。 Angular Docによると、「ジャスミンは、物事が悪く、テストが実行されていない」というジャスミンです。「クラスをインスタンス化するときにジャスミンが壊れる

奇妙なことに、BlobViewModelは機能します。 「this.const = new Constants();」をコメントまたは削除すると、それは再び働く。複数のクラスを使ってみると、常に同じ結果が得られます。クロムのログ/エラーはありません。

ジャスミン2.4.1でAngular RC4を使用しています。 これは私の.specファイルです:

import {Component, OnInit, OnDestroy } from "@angular/core"; 
import {Router} from '@angular/router'; 

import { Constants } from './shared/app.constants'; 

describe('component test',() => { 
    beforeEach(function() { 
     this.const = new Constants(); // THIS BREAKS IT 
    }); 
    it('Tests',() => { 
     //Tests come here 
     //this.const.Signalr(); 
    }); 
}); 

describe('1st tests',() => { 
    it('true is true',() => expect(true).toEqual(true));}); 

describe('BlobViewModel',() => { 
    var id = 1; 
    var localhost = "http//localhost"; 
    var fullpath = "http//fullpathtoapplication.com"; 
    var printername = "Printy print"; 
    var papersize = "A4"; 
    var blobmodel = new BlobViewModel(id, localhost, fullpath, printername, papersize); 
    it('BlobviewModel aanmaken',() => { 
     expect(blobmodel.ID).toEqual(id); 
     expect(blobmodel.FullLocalUrl).toEqual(localhost); 
     expect(blobmodel.FullPath).toEqual(fullpath); 
     expect(blobmodel.PrinterName).toEqual(printername); 
     expect(blobmodel.PaperSize).toEqual(papersize); 
    }); 
}); 

.specランナーのためのHTMLファイル:最後に

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html;charset=utf-8"> 
    <title>Ng App Unit Tests</title> 
    <link rel="stylesheet" href="../js/jasmine-core/lib/jasmine-core/jasmine.css"> 
    <script src="../js/jasmine-core/lib/jasmine-core/jasmine.js"></script> 
    <script src="../js/jasmine-core/lib/jasmine-core/jasmine-html.js"></script> 
    <script src="../js/jasmine-core/lib/jasmine-core/boot.js"></script> 


</head> 
<body> 
    <!-- #1. add the system.js library --> 
    <script src="../js/systemjs/dist/system.src.js"></script> 
    <script src="../app/Systemjs.config.js"></script> 

    <script> 
     // #2. Configure systemjs to use the .js extension 
     //  for imports from the app folder 
     System.config({ 
      packages: { 
       '../app': { defaultExtension: 'js' } 
      } 
     }); 

     // #3. Import the spec file explicitly 
     System.import('../app/file.spec.js') 

     // #4. wait for all imports to load ... 
     //  then re-execute `window.onload` which 
     //  triggers the Jasmine test-runner start 
     //  or explain what went wrong. 
     .then(window.onload) 
     .catch(console.error.bind(console)); 
    </script> 
</body> 
</html> 

答えて

0

私は、それを考え出しに「反映-メタデータを」パッケージをインポートする必要がありましたhtmlファイル:

<script src="../js/reflect-metadata/Reflect.js"></script> 
関連する問題