jasmine: Async `pending` fails the spec when used with Promises
The work done to handle global errors in async specs using the done callback correctly collects the pending exception and marks the spec appropriately. When calling pending from within a Promise returned by a spec, it is treated as a Promise failure and doesn’t mark the spec as pending.
Example suite:
it('done pends', function(done) {
setTimeout(pending, 10);
});
it('promise pends', function() {
return new Promise(function () {
pending('promise');
});
});
Output:
npm test
> tester@ test /Users/gregg/workspace/tester
> jasmine --config=jasmine.json
Started
*F
Failures:
1) promise pends
Message:
Failed: => marked Pendingpromise
Stack:
Error: Failed: => marked Pendingpromise
at runMicrotasksCallback (internal/process/next_tick.js:58:5)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at Immediate._tickCallback (internal/process/next_tick.js:98:9)
at runCallback (timers.js:651:20)
Pending:
1) done pends
No reason given
2 specs, 1 failure, 1 pending spec
Finished in 0.022 seconds
Possible Solution
It looks like the Spec object only checks for the isPendingSpecException when handling an exception, but the QueueRunner passes Promise failures along via fail which causes them to skip this logic and go directly to the expectation failure handler.
The goal of using fail in QueueRunner was to not have to duplicate the continuation logic, but it probably needs to change to handle a Promise rejection as an Error and then continue on after that.
Your Environment
- Version used: jasmine 2.8
- Environment name and version nodejs v7.5.0 (and others)
We would be happy to review a pull request that addresses this issue.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 16 (8 by maintainers)
I have the latest version of Jasmine v3.3.0 and get error when calling
pending()… 😕@rasjani this should be fixed on master now. If you have a chance, please take a look and if you’re still seeing the issue with the updated code let us know.
Thanks for using Jasmine!