I have to make some unit tests for a website made with Angular2 but im not sure how to test the components using traditional Unit testing. Example of a component i want to test:
import { Component } from '@angular/core';
import * as io from "socket.io-client";
import { SocketService } from '../global/socket.service';
import { Router } from '@angular/router';
@Component({
moduleId: module.id,
selector: 'login-app',
templateUrl: 'login.component.html',
})
export class LoginComponent {
name = 'Angular';
username: string;
password: string;
constructor(private socketService: SocketService, private router: Router){ }
loginAccount(){
var login = {
username: this.username,
password: this.password,
}
this.socketService.socket.emit('login', JSON.stringify(login));
}
ngOnInit(){
if(localStorage.getItem('user')){
this.router.navigateByUrl('/home');
}
}
}
The test class ive made so far looks like this:
import {LoginComponent} from './login.component';
describe('login' , ()=>{
it('test userinput' , ()=>{
})
})
Im not sure what test and how to test it as the functions i have do not have any parameters or returns. Any help is greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire