auto-spies icon indicating copy to clipboard operation
auto-spies copied to clipboard

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

Open brinehart opened this issue 2 years ago • 2 comments

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):

  • OS: OSX Mojave
  • Browser Jest Test Runner running in VS Code
  • Version

Additional context Package json version info:

"@angular/core": "13.2.2",
"jest-auto-spies": "^1.6.6",

brinehart avatar Jul 14 '22 14:07 brinehart

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

shairez avatar Jul 19 '22 22:07 shairez

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

If not I suggest closing this issue now.

hlovdal avatar Jan 10 '23 16:01 hlovdal