Я новичок в модульном тестировании в Angular.Есть ли способ, кроме этого, написать модульные тесты для этой конкретной функции?Спасибо!
list-user.component.ts
constructor(private auth: AuthenticationService, private router: Router, private dialog: MatDialog) { }
fetchOfficeInfoByManager() {
this.auth.getUserbyLM().subscribe((data: User[]) => {
this.usersource = new MatTableDataSource(data);
}
ngOnInit() {`
this.fetchOfficeInfoByManager();
}
list-user.component.spec.ts
import { ListUserComponent } from './list-user.component';
import { AuthenticationService } from '../../shared/services/authentication.service';
import { Observable } from 'rxjs';
import { from } from 'rxjs'
describe ('ListUserComponent', () => {
let component: ListUserComponent;
let service: AuthenticationService;
beforeEach(() => {
service = new AuthenticationService(null, null);
component = new ListUserComponent(service, null, null);
});
it('should get employees according to line manager', () => {
let data = [];
spyOn(service, 'getUserbyLM').and.callFake(() => {
return from([ data ]);
});
component.fetchOfficeInfoByManager();
expect(component.data).toBeTruthy();
});
});