I am new to angular unit testing and I have tried to write test cases for service file. I need to write test cases for below code
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class EmployeeDetailsService {
private readonly employeeRoles = new BehaviorSubject<any>([]);
private readonly isEmployeeData = new BehaviorSubject<boolean>(true);
employeeRolesData = this.employeeRoles.asObservable();
isEmployee = this.isEmployeeData.asObservable();
addEmployeeRoles(data: string) {
this.employeeRoles.next(data);
}
checkIsEmployee(data: boolean) {
this.isEmployeeData.next(data);
}
}
what I have tried is
import { TestBed } from '@angular/core/testing';
import { EmployeeDetailsService } from './EmployeeDetails.service';
describe('EmployeeDetailsService', () => {
let service: EmployeeDetailsService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(EmployeeDetailsService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
it('addEmployeeRoles', () => {
service.addEmployeeRoles.subscribe(data => {
expect(data).toEqual(data);
})
});
it('checkIsEmployee', () => {
service.checkIsEmployee.subscribe(data=>{
expect(data).toEqual(data)
})
});
})
Unit test cases are passing, but code coverage is not improving. So please help me to solve this.