How to write Unit test case for below function

Published

Below code is working but code is not written as it is supposed to do. Because function is returning something but I as per my unit test function is returning value

TS Code:

checkSelectionFromDeletable() {
    return this.numbersFacade.selectedRows$.pipe(
      map(selectedRowCapsule =>
        selectedRowCapsule?.selectedRows.find(x => x.owner || x.mainNumberFlag)
      )
    );
 }

spec.ts

it('should test checkSelectionFromDeletable', () => {
      const rowData  = of({
        phoneNumber: '12345678',
        extension: '',
        numberType: 'MAIN',
        state: 'US',
        location: '',
        locationId: '',
        mainNumberFlag: false,
        tollFreeFlag: false,
        owner: 'test'
      } as ICallNumberVM)
      component.checkSelectionFromDeletable();
      numbersFacade.selectedRows$.subscribe(res => {
        expect(res).toEqual(rowData);
      });
    });

Source: Angular Questions

Published
Categorized as angular, jasmine, rxjs, typescript, unit-testing Tagged , , , ,

Answers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq