2017-05-04 5 views
2

내 component.ts 파일과 같이 보인다Jamine 단위 테스트 오류가

import { Component, OnInit } from '@angular/core'; 
import { select } from 'ng2-redux'; 
import { Observable } from 'rxjs/Observable'; 
import { PersonalDetailsComponent } from '../personal-details/personal-details.component' 

@Component({ 
    selector: 'app-profile-details', 
    templateUrl: './profile-details.component.html' 
}) 
export class ProfileDetailsComponent implements OnInit { 

    @select(['customerData', 'personalDetails'])personalDetails:Observable<object>; //<------if i comment out @select statement, then the tests work 
    @select(['loading']) loading: Observable<boolean>;//<------if i comment out @select statement, then the tests work 

    constructor() { } 

    ngOnInit() { } 

} 

그리고 내 자스민 시험이

import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 
import { NgRedux, select } from 'ng2-redux'; 
import { ProfileDetailsComponent } from './profile-details.component'; 
import { customerData } from '../data/customerProfileDataMock'; 
import { PersonalDetailsComponent } from '../personal-details/personal-details.component' 
import { Router } from '@angular/router'; 
import { Observable } from 'rxjs/Observable'; 

class RouterStub { navigate(params) { } } 
class MockSelect { } 
class MockObservable<T> {} 
class NgReduxStub { 
    constructor() { } 
    dispatch =() => undefined; 
    getState =() => { return customerData; }; 
    subscribe =() => undefined; 
} 

describe('ProfileDetailsComponent',() => { 
    let component: ProfileDetailsComponent; 
    let fixture: ComponentFixture<ProfileDetailsComponent>; 

    beforeEach(async(() => { 
    TestBed.configureTestingModule({ 
     declarations: [ProfileDetailsComponent, PersonalDetailsComponent], 
     providers: [ 
     { provide: Router, useClass: RouterStub }, 
     { provide: select, useClass: MockSelect }, 
     { provide: NgRedux, useClass: NgReduxStub }, 
     { provide: Observable, useClass: MockObservable } 
     ], 
    }) 
     .compileComponents(); 
    })); 

    beforeEach(() => { 
    fixture = TestBed.createComponent(ProfileDetailsComponent); 
    component = fixture.componentInstance; 
    fixture.detectChanges(); 
    }); 

    it('should create the profile details page',() => { 
    expect(component).toBeTruthy(); 
    }); 

}); 

처럼 뭐죠 누락 확인하지만, 안 보이는 아래 @ 난 당신이 경우 테스트 'NG 테스트'

TypeError: ng_redux_1.NgRedux.instance is undefined in src/test.ts 

답변

0

확실하지를 명령을 사용하여 실행하면 select 문을 조롱하고 아래의 오류가 점점되지 않는다 내가 같은 패키지를 사용하고 있지만 npm (https://www.npmjs.com/package/ng2-redux)의 ng2-redux가 github 저장소 https://github.com/angular-redux/store에 연결되므로 분기가 병합되었을 수도 있습니다.

그렇다면 패키지 업데이트를 제안합니다. 그들은 최근에 당신이

beforeEach(() => { 
    TestBed.configureTestingModule({ 
    imports: [ 
     NgReduxTestingModule, 
    ], 

와 테스트 베드에 추가됩니다

import { NgReduxTestingModule, MockNgRedux } from '@angular-redux/store/testing'; 

과 테스트에 추가 할 수 있으며 특정 선택기에 값을 설정하여 @select()를 사용하는 구성 요소를 테스트하는 데 사용할 수있는 MockNgRedux을 추가 한

const stub = MockNgRedux.getSelectorStub(selector); 
stub.next(values); 
stub.complete(); 

메소드가 정적이며 MockNgRedux 인스턴스가 필요하지 않습니다.

하는 테스트 사이의 모의 상점을 취소해야합니다

beforeEach(() => { 
    MockNgRedux.reset(); 
});