i have some service like this
calendar-domain.service.ts
@Injectable()
export class CalendarDomainService {
private _calendarWeek = new BehaviorSubject<CalendarWeekTo | null>(null);
get calendarWeek$(): Observable<CalendarWeekTo | null> {
return this._calendarWeek.asObservable();
}
setCalendarWeek(calendarWeek: CalendarWeekTo): void {
this._calendarWeek.next(calendarWeek);
}
}
And unit test like this
calendar-domain.service.spec.ts
import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { CalendarDomainService } from './calendar-domain.service';
describe('CalendarDomainService', () => {
let service: CalendarDomainService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [CalendarDomainService],
schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA]
});
service = TestBed.inject(CalendarDomainService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
As you may see i didn't test those two function, because honest I don't know how even to start testing, any info about how to start, thanks
CodePudding user response:
You can use the done Callback on the test itself and subscribe normally to the subject.
it('Should emit next value of the week', (done)=>{
service.setCalendarWeek(<yourvaluehere>);
service.calendarWeek$.subscribe(v=> {
expect(v).toBe(<yourvaluehere>)
done();
});
});