0

I am trying to test an Observable using RxJS marbles. the following is my code: at point x i want to login and at point y i want to add new invoices to my list. The problem is, that it always says that there are already invoices at frame 1 addToInvoiceList just adds the element to the list if we are logged in.

here is the test code:

testScheduler.run(({ expectObservable, cold, hot, flush }) => {
          cold('-x-y-', {
            x: 'authenticate',
            y: 'addToInvoiceList',
          }).subscribe(value => {
            if (value === 'authenticate') {
              qdAuthMock.isAuthenticated$.next(true);
            } else if (value === 'addToInvoiceList') {
              sut.addToInvoiceList({ ...mockedInvoice, invoiceId: '5' });
            }
          });

          const invoicesFromBackendObservable = sut.invoicesFromBackend$;

          expectObservable(invoicesFromBackendObservable).toBe('a-ab-', {
            a: [],
            b: [{ ...mockedInvoice, invoiceId: '5' }],
          });
        });

I would greatly appreciate any help or tipps.

timmmmmb
  • 674
  • 7
  • 26
  • What's `sut.invoicesFromBackend$`? Provide a https://stackoverflow.com/help/minimal-reproducible-example – Lin Du Jun 22 '23 at 04:16

0 Answers0