Usando Angular 16 e Jasmine/Karma.
Eu tenho esta assinatura para um assunto de comportamento chamadotableList$
ngOnInit() {
const { pageNumber } = this.subscribersService.getMiscValues();
this.subscribersService.initPage(pageNumber);
>> this.subscribersService.tableList$.subscribe((tableList) => {
// this.tableList = this.deleteSubscribersService.setDeleteCheckboxStates(tableList);
});
}
Estou tentando zombar do assunto comportamento, mas estou conseguindo this.subscribersService.tableList$.subscribe is not a function
.
Alguma idéia do que estou fazendo de errado, por favor?
Observe, eu também tentei subscribersServiceMock.tableList$.and.returnValue({ subscribe: () => tableListMock$.subscribe });
sem sucesso
fdescribe('ManageSubscribersComponent', () => {
let component: ManageSubscribersComponent;
let fixture: ComponentFixture<ManageSubscribersComponent>;
let miscMockValues;
let tableMockData;
let tableListMock$;
let dialogServiceMock
let dialogSubjectMock;
let subscribersServiceMock;
let deleteSubscribersServiceMock;
const displayedColumns = [
'id',
'name',
'description',
'createdBy',
'createdOn',
'updatedBy',
'updatedOn',
];
beforeEach(() => {
tableListMock$ = new Subject();
dialogSubjectMock = new Subject();
dialogServiceMock = jasmine.createSpyObj([
'open',
'afterClosed',
]);
deleteSubscribersServiceMock = jasmine.createSpyObj([
'deleteSubscribers',
]);
subscribersServiceMock = jasmine.createSpyObj([
'resetMiscValues',
'getMiscValues',
'initPage',
'tableList$',
]);
miscMockValues = {
pageNumber: 1,
pageSize: 25,
sort: '',
active: true,
testMode: false,
searchTerms: '',
};
subscribersServiceMock.getMiscValues.and.returnValue(miscMockValues);
subscribersServiceMock.tableList$.and.returnValue(tableListMock$);
dialogServiceMock.afterClosed.and.returnValue(dialogSubjectMock);
TestBed.configureTestingModule({
declarations: [ManageSubscribersComponent],
imports: [
HttpClientTestingModule,
MatFormFieldModule,
MatIconModule,
MatSliderModule,
MatTableModule,
MatFormFieldModule,
MatInputModule,
BrowserAnimationsModule,
MatPaginatorModule,
MatDialogModule,
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA,
NO_ERRORS_SCHEMA,
],
providers: [
{
provide: SubscribersService,
useValue: subscribersServiceMock,
},
{
provide: DeleteSubscribersService,
useValue: deleteSubscribersServiceMock,
},
],
});
fixture = TestBed.createComponent(ManageSubscribersComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fit('should init', fakeAsync(() => {
fixture.whenStable().then(() => {
expect(component.displayedColumns).toEqual(displayedColumns);
expect(subscribersServiceMock.getMiscValues).toHaveBeenCalled();
})
}));