Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: #15223

Open
brunouber opened this issue Jul 31, 2024 · 2 comments
Open

[Bug]: #15223

brunouber opened this issue Jul 31, 2024 · 2 comments

Comments

@brunouber
Copy link

brunouber commented Jul 31, 2024

Version

29.7.0

Steps to reproduce

I can't reproduce it on a different (or simpler) project than the one where is currently occurring.

Expected behavior

Jest runs test correctly.

Actual behavior

TypeError: debug is not a function

> 5 | import fetchMock from 'fetch-mock';
    | ^
    6 |
    7 | import { render, screen, waitFor } from '@testing-library/react';
    8 | import userEvent from '@testing-library/user-event';

    at newDebug (node_modules/fetch-mock/cjs/lib/debug.js:14:5)
    at Object.<anonymous> (node_modules/fetch-mock/cjs/lib/debug.js:19:1)
    at Object.<anonymous> (node_modules/fetch-mock/cjs/lib/index.js:1:121)
    at Object.<anonymous> (node_modules/fetch-mock/cjs/server.js:15:19)
    at Object.<anonymous> (frontend/js/demo.test.tsx:5:1)

Additional context

You won't like this.

I've read your submission guidelines, but this time I can't (as I am not be able to) recreate a simple test scenario...
I understand this is a bummer, but please, before closing the issue, read it and you'll understand why is that.
You might be still be able to point me in the right direction.

I'm the only person in my team (yay) who could reproduce it, despite having all the same node version and dependencies installed.

We have several tests files.
Some of these use fetch-mock (latest version).

The problem appears only in the files using fetch-mock.

TypeError: debug is not a function

> 5 | import fetchMock from 'fetch-mock';
    | ^
    6 |
    7 | import { render, screen, waitFor } from '@testing-library/react';
    8 | import userEvent from '@testing-library/user-event';

    at newDebug (node_modules/fetch-mock/cjs/lib/debug.js:14:5)
    at Object.<anonymous> (node_modules/fetch-mock/cjs/lib/debug.js:19:1)
    at Object.<anonymous> (node_modules/fetch-mock/cjs/lib/index.js:1:121)
    at Object.<anonymous> (node_modules/fetch-mock/cjs/server.js:15:19)
    at Object.<anonymous> (frontend/js/demo.test.tsx:5:1)

debug is defined as const debug = require('debug'); and it's correctly installed in my repository.
In fact, I've added some logs here and there, and it's also executed.

What is most surprising to me is what I get in the console when I log the content of debug:

{
    id: 'journal_benchmarking_dev',
    label: 'Journal Benchmarking DEV',
    description: 'Development version',
    ...
}

It's an object that looks like something that makes sense in our domain, but it doesn't have nothing to do with jest, or jest-mock.

I imagined this could be caused by some symbol resolution conflict, but what makes this hard to accept is that if i perform a string search in the repository for any of the labels in the object (eg "journal_benchmarking_dev") I can't find any match.

I understand the Jest run tests on the source files, performing JIT compilation... is there any way to inspect the actual source code Jest is using for the test?

Do you have any idea what might be causing this problem, or how to fix it?
I've already tried almost everything:

  • clear jest cache
  • update jest
  • using fetch-mock-jest
  • delete/reinstall node_modules
  • different versions of node

Environment

System:
    OS: macOS 14.4.1
    CPU: (11) arm64 Apple M3 Pro
  Binaries:
    Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
    npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
@brunouber
Copy link
Author

brunouber commented Jul 31, 2024

Further findings:

  1. If i replace const debug = require('debug'); in node_modules/fetch-mock with const debug = require('abs/path/to/debug'); then everything works fine.

  2. The problem seems unrelated to fetch-mock. In fact, if I inspect debug in a file that is not using fetch-mock I can still see the wrong value... but this doesn't break the test cause debug is not used unless also fetch-mock is used.

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant