2016-08-16 5 views
0

Jasmine을 사용하여 Angular 2 앱의 테스트를 작성하려고합니다. 몇 가지 자습서를 따라 많은 시도. 기본 테스트와 함께 작동하지만 구성 요소의 인스턴스를 만들거나 모의하려고하면 테스트 결과가 표시되지 않습니다. Angular Doc에 따르면 그것은 '재 스민 (Jasmine)'입니다. 상황이 너무 나빠서 테스트를 실행하지 못한다고합니다. '클래스를 인스턴스화 할 때 Jasmine이 깨집니다.

이상하게도 BlobViewModel이 작동합니다. 코멘트 또는 삭제할 때마다 'this.const = new Constants();' 다시 작동합니다. 여러 클래스를 사용해 보았는데 항상 같은 결과를 얻습니다. 크롬에 로그/오류가 없습니다.

우리는 재스민 2.4.1과 함께 각도 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); 
    }); 
}); 

HTML 파일 : 이 내을 .spec 파일 내가 그것을 알아 냈 결국

<!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> 
관련 문제