2016-10-10 4 views
0

I는 다음 설치와 각도이 구성 요소를 테스트하기 위해 노력하고있어 :각도 2 테스트 설정

import { TestBed } from '@angular/core/testing'; 
import { By }  from '@angular/platform-browser'; 

import { GroceriesListComponent } from './groceries-list.component'; 
import { GroceryService }  from './grocery.service'; 

let comp: GroceriesListComponent; 
let fixture: ComponentFixture<GroceriesListComponent>; 

beforeEach(() => { 
    TestBed.configureTestingModule({ 
    declarations: [GroceriesListComponent], 
    providers: [GroceryService] 
    }); 

    fixture = TestBed.createComponent(GroceriesListComponent); 
    comp = fixture.componentInstance; 

    _groceryService = fixture.debugElement.injector.get(GroceryService); 

    spy = spyOn(_groceryService, 'getGroceries') 
    .and.returnValue(Promise.resolve(testGroceries)); 

    de = fixture.debugElement.query(By.css('li')); 
    el = de.nativeElement; 
}); 

...하지만이 정보의 부족으로 내 콘솔에 인해 다음과 같은 오류가 계속

404: /base/traceur 
ERROR 
{ 
    "originalErr": {} 
} 

답변

0

이 정말 성가신 오류가 나는 "traceur는"SystemJS transpiler의 기본값입니다 것을 깨달았 때까지 약간의 시간이 걸렸습니다 : 오류 메시지가 나는 내 설정에 어떤 문제가 있는지에 관해서는 잃었어요.

다음과 같은 솔루션은 그래서 타이프 라이터가 transpiler 얻는 두 파일 (karma.conf.js와 카르마 - 테스트 shim.js)를 적용했다 :

karma.conf.js을

module.exports = function(config) { 
 
    config.set({ 
 

 
    basePath: '', 
 

 
    frameworks: ['jasmine'], 
 

 
    files: [ 
 
     // Polyfills. 
 
     'node_modules/es6-shim/es6-shim.js', 
 

 
     // .. more files such as reflect, systemjs, zones, rxjs ... 
 

 
     // load typescript as well !!!!!!!!!!!!!!!!!!!!!!! 
 
     { pattern: 'node_modules/typescript/**/*.js', included: false, watched: false }, 
 
     { pattern: 'node_modules/typescript/**/*.js.map', included: false, watched: false }, 
 

 
     { pattern: 'karma-test-shim.js', included: true, watched: true}, 
 
\t 
 
     // load angular and your own code 
 

 
    ], 
 

 
    // proxied base paths 
 
    proxies: { 
 
     // required for component assests fetched by Angular's compiler 
 
     "/dist/": "/base/dist/" 
 
    }, 
 

 
\t // karma config ... 
 
\t 
 
    singleRun: false 
 
    }) 
 
}

카르마 - 테스트 shim.js

// Load our SystemJS configuration. 
 

 
System.config({ 
 
    baseURL: '/base' 
 
}); 
 

 
System.config(
 
    { 
 
     // set the transpiler here !!!!! 
 
     transpiler: 'typescript', 
 
     paths: { 
 
      // paths serve as alias 
 
      'npm:': 'node_modules/' 
 
     }, 
 
     map: { 
 
      'dist': 'dist', 
 
\t \t \t 
 
      // mapping for typescript !!!!!!!!!!!!! 
 
      'typescript': 'npm:typescript/lib/typescript.js', 
 
\t \t \t 
 
      // ... more mappings 
 
\t \t \t 
 
      // other libraries 
 
      'rxjs': 'npm:rxjs' 
 
     }, 
 
     packages: { 
 
      'dist': { 
 
       defaultExtension: 'js' 
 
      }, 
 
      'rxjs': { 
 
       defaultExtension: 'js' 
 
      } 
 
     } 
 
    }); 
 

 
Promise.all([ 
 
    System.import('@angular/core/testing'), 
 
    System.import('@angular/platform-browser-dynamic/testing') 
 
]).then(function (providers) { 
 
\t // ... 
 
}).then(function() { 
 
\t // ... 
 
}).then(__karma__.start, __karma__.error);