Inconsistent `jest.fn()` behavior

Open
#24 2 comments 0 reactions 0 assignees View on GitHub

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

bug

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ExodusOSS/test

All issues in ExodusOSS/test

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.