0
현재 Karma 및 Jasmine과 함께 Angular2에 대한 단위 테스트를 작성하고 있지만 단위 테스트에서는 새로운 것이므로 몇 가지 어려움에 직면하고 있습니다. 비동기 함수 또는 비동기 함수를 포함하지 않는 속성을 테스트 할 때는 모두 괜찮습니다. 그러나 일부 변수가 값을 가져 오려면 구성 요소 함수를 호출 할 수 있어야합니다. 어떻게 내가 뭘하면 다음과 같다 :Angular2 - 테스트 된 구성 요소의 호출 함수
내 구성 요소 :
export class LoginComponent implements OnInit {
formLoginId: string;
loginUrl: string;
email: string;
password: string;
constructor(private googleAuthService: GoogleAuthService,
private authService: AuthenticationService,
private validationService: ValidationService,
private router: Router,
private titleService: Title) {
this.titleService.setTitle("Login");
this.formLoginId = "#form-login";
}
ngOnInit() {
this.googleAuthService.getLink((response) => {
this.loginUrl= response.json().url;
});
}
login() {
if (this.validationService.isValid(this.formLoginId)) {
this.authService.login(this.email, this.password);
}
}
지금 나는 loginUrl은 어떤 가치를 가지고있는 경우 확인할 수 있습니다 단위 테스트를 작성하고자합니다. 내 테스트가 울부 짖음 :
describe('Login Component',()=> {
let component:LoginComponent;
let fixture:any;
beforeEach(async(()=> {
TestBed.configureTestingModule({
//declarations,imports and providers
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
}); /some-other-tests/
it('should have login url', fakeAsync(()=> {
component.ngOnInit();
tick(1000);
expect(component.loginUrl).toBeDefined();
}));
});
하지만 작동하지 않는 것 같습니다. 언급 된 변수에 대해 아직 정의되지 않았습니다. 구성 요소에서 메서드를 호출하고 그 결과를 확인하는 방법은 무엇입니까?
감사합니다.