I have the following simple test setup:
test('what did I do to deserve this', async () => {
expect.assertions(1)
const data = await fetchData() // or fetchData2
expect(data).toBe('peanut butter')
})
async function fetchData () {
return "peanut butter"
}
async function fetchData2 () {
return knex.select('name').from('foos')
}
When I use fetchData
jest finishes happily.
But when I use fetchData2
it complains of this:
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with
--detectOpenHandles
to troubleshoot this issue.
The data variable does have the result from the db query, and other callers higher in the API resolve the query fine and continue the execution of other statements.
I have tried:
- the
--detectOpenHandles
flag but it doesn't show me anything. - making the expect pass for
fetchData2
in case it was the issue described here - passing a
done
arg to the async function intest
. It does exist, but calling it does not fix the warning. - throwing try/catch blocks at it
Thanks for any help on making this happy.
Versions of things:
- Node v11.1.0
- "jest": "^23.6.0"
- "knex": "^0.15.2"