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

require.resolve is not a function when using jest.mock #692

Comments

@FDiskas
Copy link
Contributor

FDiskas commented Apr 3, 2018

Trying to mock something with jest and got require.resolve is not a function
https://codesandbox.io/s/003vnm1wrn?module=%2Fsrc%2Ftests%2FHello.test.tsx
error

@CompuIves
Copy link
Member

Ahh, yes good one. We need to build jest.mock support since we use our own resolver and executor for modules.

I will try to build this this week, regardless I'll keep this issue open for everyone to pickup in the meantime.

We need to get all jest.mock calls and add them to the aliases field on Manager. I think that should do the trick and make jest.mock work.

@FDiskas
Copy link
Contributor Author

FDiskas commented Apr 5, 2018

jest.spyOn is another one :)

@the0neWhoKnocks
Copy link

the0neWhoKnocks commented May 18, 2018

Not sure if it's related, but I'm seeing similar behavior with enzyme. I have a jest.config.js file that works fine locally but seems to be ignored in the sandbox. When I inline the jest config into the package.json it still doesn't load the setupTestFrameworkScriptFile or setupFiles files. So I then tried to add the enzyme configuration code at the top of my test files and got more errors. Here's the URL to the import of my repo https://codesandbox.io/s/github/the0neWhoKnocks/app-console/tree/master/

I didn't find anything regarding enzyme in the issues, but after reading that you have to build support for frameworks, maybe enzyme also needs to be added to the pile.

jest.useFakeTimers() doesn't work either.

In the meantime, is there a way to disable tests in the sandbox?

@FDiskas
Copy link
Contributor Author

FDiskas commented May 21, 2018

Did you tried to install https://www.npmjs.com/package/enzyme-adapter-react-16 and https://www.npmjs.com/package/enzyme
?:goat:
It works if you add all configuration to each test file
https://codesandbox.io/s/vm6xrzp0y7

@the0neWhoKnocks
Copy link

@FDiskas yeah I tried that, but that's not a solution when jest has setupTestFrameworkScriptFile built in. Also, even after doing that, a lot of tests didn't work due to the usage of mock and useFakeTimers. It'd be nice if in the meantime, codesandbox would display a message saying "sorry, these testing features aren't available" or "these tests have been disabled due to lack of api support". Something along those lines so consumers don't waist time debugging their code. Honestly I'd be fine with the ability to just toggle tests off, I saw there was a way to toggle watching of files off, but the tests would still run at least once throwing inaccurate errors.

@FDiskas
Copy link
Contributor Author

FDiskas commented May 21, 2018

@the0neWhoKnocks so lets wait for #513

@github-actions
Copy link

github-actions bot commented Sep 4, 2020

This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

@github-actions github-actions bot added the stale label Sep 4, 2020
@github-actions
Copy link

github-actions bot commented Oct 1, 2020

This issue has been automatically closed because there wasn't any activity after the previous notice or the stale label wasn't removed.

@github-actions github-actions bot closed this as completed Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment