Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6290

Jest async test fails because void Promise never resolves

$
0
0

I am writing tests in Jest for a react-native project, and for some unknown (to me) reason, async tests are failing due to timeout without resolution. As far as I can tell, the promises related to the tests themselves do not seem to be resolving correctly wherever the Jest test itself uses an async block:

    describe('test', () => {        const withVoidPromise = async (): Promise<void> => {            console.log('async function with wrapped void promise.')        }        it('example void promise test', async () => {            await withVoidPromise()            console.log('void promise test passed')        })        const explicitResolvedPromise = async (): Promise<void> => {            console.log('async function with explicitly resolved promise.')            return Promise.resolve()        }        it('example explicitly resolved test', async () => {            await explicitResolvedPromise()            console.log('explicitly resolved test passed')        })    })

yields:

yarn run v1.22.19$ npx jest Test  console.log    async function with wrapped void promise.      at log (__tests__/TelemetryHelperTest.ts:193:21)  console.log    async function with explicitly resolved promise.      at log (__tests__/Test.ts:202:21) FAIL  __tests__/Test.ts (11.395 s)  testHelper    upload✕ example void promise test (5003 ms)✕ example explicitly resolved test (5001 ms)

I am using Jest 29.3.1 with Typescript 4.9.4


Viewing all articles
Browse latest Browse all 6290

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>