You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using jest to write a test for a angular 12 component. I would like to use receivedNext() in a specific way, but it doesn't do what I would expect.
Here is an example:
// I create a spy to a observable, which emits some values when submit$ emits but// ONLY WHEN service returns something.jest.spyOn(mockService,'load').mockReturnValue(of(values));constvaluesSpy=subscribeSpyTo(component.values$);// submitcomponent.submit$.next();tick();expect(valuesSpy.receivedNext()).toBe(true);// works until here// now I want to submit again, but with no values being returnedjest.spyOn(mockService,'load').mockReturnValue(of(null));// now submit againcomponent.submit$.next();tick();expect(valueSpy.receivedNext()).toBe(false);// fails, but I would expect that it passes, since it did not emit since the last tick() or the last time I checked.
(The component which is tested here, is implemented declaratively.)
Expected Behaviour
I would expect that receivedNext() would indicate if the observable was "nexted" again AFTER the last time I checked.
So once receivedNext() is called, it resets it. For example when called directly after I would assume that it means "received next two times in a row":
It would also be awesome if it would "reset" when using tick (inside fakeAsync()). "Received next since the last time something changed". For exmaple:
// check/emit something but don't use receivedNext here// then do something againtick();// tick to forward in time which should reset receivedNextexpect(valueSpy.receivedNext()).toBe(false);// works, since it did not emit since the last tick()
(I could use this in my use case example, to only check at the end that it was not emitted.)
Possible Solutions
Change the behaviour of .receivedNext()
Add a optional parameter. I.e. .receivedNext({ sinceLastTimeChecked: true }) - It would be nice if I could configure the lib in a way that this is the default.
Make it a new function .receivedNextSinceLastTimeChecked() - This is my least favorite option
Work Around
I know it is easily possible to use .getValues() or .getValuesLength() to check if something emitted again but for that I need to know how often it already emitted, which can change while updating the test. Therefore it would be nicer to use .receivedNext() instead.
Additional context
I am using angular v12. RxJS v6 and @hirez_io/observer-spy v2.2.
The text was updated successfully, but these errors were encountered:
Use Case / Problem
I am using jest to write a test for a angular 12 component. I would like to use
receivedNext()
in a specific way, but it doesn't do what I would expect.Here is an example:
(The component which is tested here, is implemented declaratively.)
Expected Behaviour
I would expect that
receivedNext()
would indicate if the observable was "nexted" again AFTER the last time I checked.So once
receivedNext()
is called, it resets it. For example when called directly after I would assume that it means "received next two times in a row":It would also be awesome if it would "reset" when using
tick
(insidefakeAsync()
). "Received next since the last time something changed". For exmaple:(I could use this in my use case example, to only check at the end that it was not emitted.)
Possible Solutions
.receivedNext()
.receivedNext({ sinceLastTimeChecked: true })
- It would be nice if I could configure the lib in a way that this is the default..receivedNextSinceLastTimeChecked()
- This is my least favorite optionWork Around
I know it is easily possible to use
.getValues()
or.getValuesLength()
to check if something emitted again but for that I need to know how often it already emitted, which can change while updating the test. Therefore it would be nicer to use.receivedNext()
instead.Additional context
I am using angular v12. RxJS v6 and @hirez_io/observer-spy v2.2.
The text was updated successfully, but these errors were encountered: