hirezio / auto-spies

Create automatic spies from classes
MIT License
180 stars 30 forks source link

Code inside async method with 'await [...].toPromise' stops execution #65

Open brinehart opened 2 years ago

brinehart commented 2 years ago

Describe the bug When .toPromise is called on a spied on method with a .nextWith the code stops execution

To Reproduce Steps to reproduce the behavior:

  1. In the test call nextWith on a spied on method
  2. The spied on method is called with as await <<spy>>.<<method>>.toPromise() inside an async method
  3. Step through
  4. The next line in the method never gets hit and no errors are caught

Expected behavior When called as toPromise() the observable should be cast as a Promise and when awaited should return the current value. Then jest debugger should not stop execution of the method and continue stepping through the code on the next line.

Screenshots Screen Shot 2022-07-14 at 10 21 36 AM

Desktop (please complete the following information):

Additional context Package json version info:

"@angular/core": "13.2.2",
"jest-auto-spies": "^1.6.6",
shairez commented 2 years ago

AFAIK- toPromise waits for the observable to be completed before resolving.

nextWith keeps the observable open.

Try using nextOneTimeWith instead, as it completes after sending the value.. it should solve your issue

Let me know if you run into any other issues

hlovdal commented 1 year ago

@brinehart Did you have success with the suggested solution/other feedback?

If not I suggest closing this issue now.