Do you want to request a feature or report a bug?
bug
What is the current behavior?
test('should return 1', async () => {
const fd = await open('src', 'r')
const buffer = Buffer.alloc(1)
const { bytesRead } = await read(fd, buffer, 0, 1, 0)
expect(bytesRead).toEqual(1)
})
Received: undefined
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.
What is the expected behavior?
Receive 1 instead of undefined
If this method is invoked as its util.promisify()ed version, it returns a Promise for an object with bytesRead and buffer properties.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest is 20.0.4. Node: 8.4.0, Npm: 5.3.0, OS: macOS Sierra
Node 8.1.3, Windows 10 x64, Jest 20.0.4, reproduced.
For now, it would be helpful to throw a warning that util.promisify may not function properly in jest tests...
Similar issue here. https://github.com/sindresorhus/got/issues/811
The reproduction in the repl.it in the OP does not reproduce the wrong behavior on the latest version of Jest. The test now fails with this error, which seems expected?:

The linked issue from got works fine if I remove micro, which I've never heard of and have no idea what does. And it just times out if I do not remove it, it doesn't fail like the linked issue says it does

Can someone put together a reproduction that fails with Jest 24.8.0?
Deleting micro doesn't work for me. I'm using [email protected] and [email protected].

And I don't think micro causes the problem. It just handles several cases that its request handler is returning or throwing something without calling res.end. https://github.com/zeit/micro/blob/master/packages/micro/lib/index.js#L25
Can you put together a reproduction I can pull down and run?
Oh, make sure you are using the node environment, and not the jsdom one: https://jestjs.io/docs/en/configuration#testenvironment-string
I'm using node env.
{
"preset": "ts-jest",
"testEnvironment": "node",
"testPathIgnorePatterns": [
"/node_modules/",
"/dist/"
]
}
I'll make a repo soon.
@SimenB https://github.com/Rokt33r/jest-repro-promisify Sorry for being late.
@SimenB Ping.
@Rokt33r your issue is #2549. In particular this line is false meaning the callback passed as options is not assigned to cb.
I opened up https://github.com/salesforce/tough-cookie/pull/158 which fixes the issue and makes your test work correctly in Jest.
util.promisify works correctly, so I'll close this issue
Most helpful comment
@Rokt33r your issue is #2549. In particular this line is
falsemeaning the callback passed asoptionsis not assigned tocb.I opened up https://github.com/salesforce/tough-cookie/pull/158 which fixes the issue and makes your test work correctly in Jest.
util.promisifyworks correctly, so I'll close this issue