Skip to content

Inconsistent jest.fn() behavior #24

Description

@sparten11740

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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions