Inconsistent `jest.fn()` behavior
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, node.js
- Domain
- testing
Research direction
Start by comparing the exodus-test implementation of jest.fn() with node:test's mock.fn(), using the callback examples in the issue to reproduce the timing difference. Done means the call count is observable inside the mocked implementation callback, with coverage for the demonstrated behavior.
Written by the indexing model from the issue text.
Description
When using jest.fn() from jest with a mocked implementation, the call count is eagerly updated and can be asserted against inside the implementation callback. The exodus-test implementation of jest.fn() does not do that as it depends on node's mock.fn() which only updates the call count after the callback returns.
To demonstrate the issue, the below logs a call count of 0:
import { mock } from 'node:test'
const mockedFn = mock.fn(() => {
console.log(mockedFn.mock.callCount())
})
mockedFn()
The following (using jest's impl) however logs a call count of 1:
const mockedFn = jest.fn(() => {
console.log(mockedFn.mock.calls.length)
})
mockedFn()
- Dominant language
- JavaScript
- Stars
- 18
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ExodusOSS/test
-
ladybird-js support Openblocked: upstream bug
Difficulty 4/5 3-5 days Newbie friendliness 42/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·