Promise hangs when resolving a mocked instance
See original GitHub issueWhen a Promise wraps a mocked instance, it never resolves but hangs.
const { mock, instance } = require('ts-mockito')
const MockConnector = mock()
const connector = instance(MockConnector)
function connectorFactory() {
return Promise.resolve(connector) // <== This mock instance (Proxy object) never get resolved by Promise.
}
(async () => {
const created = await connectorFactory() // <== This Promise hangs forever.
console.log('Connector created') // <== Never reached
})()
This issue is same with #155 which never gets noticed nor replied. A runnable sandbox: https://runkit.com/embed/5ljjgubxm9fm
Issue Analytics
- State:
- Created 4 years ago
- Reactions:13
- Comments:9
Top Results From Across the Web
How do I resolve Promise in mocked function? - Stack Overflow
If you want to create a promise which is already resolved, you can simply use Promise.resolve(someData). In your case it should be something ......
Read more >Asynchronous Behavior | Vue Test Utils
For scenarios like this, Vue Test Utils exposes flushPromises , which causes all outstanding promises to resolve immediately. Let's see an example:.
Read more >API Docs | fetch-mock - Wheresrhys
11.0. Returns a Promise that resolves once all fetches handled by fetch-mock have resolved. Useful for testing code that uses ...
Read more >A Helpful Guide to Testing Promises Using Mocha - Testim Blog
Check out this example: Async/await promise test. And those are really the quickest ways to get your Mocha tests working with async code....
Read more >How to implement a request timeout using the Promise.race ...
Learn the 24 patterns to solve any coding interview question without getting ... As a result, our request will be left hanging. ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For now, this is my workaround
JavaScript:
TypeScript:
Useage example:
@NagRock why this issue has not been addressed for such a long time?