-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Jest in CodeSandbox 3.0 #513
Comments
also cc @gillchristian - interested to help with code or ideas? :) |
Yeah, I just joined Discord, we can talk there 😄 |
|
@alexilyaev indeed, in the Discord I mentioned I'd like to work on it but haven't found the time yet 😬 |
Fake timers 🙏
|
Just came across this ticket after commenting on another ticket #692 (comment). There may be issues utilizing To clarify, people will have issues running enzyme if they utilize setupTestFrameworkScriptFile like is suggested in the official enzyme docs https://github.com/airbnb/enzyme/blob/master/docs/guides/jest.md#configure-with-jest |
Would have been nicer when I called |
or |
+1 As local code works fine, the "not a function" error is a bit misleading (to me anyways), as I literally found out about CodeSandbox today (super awesome BTW!) and trying to use it to testdrive react components and jest tests. Not knowing the architecture, I just assumed that if Jest was in the dependencies correctly, I could call any of the jest.x() functions. |
So I've read this thread over 3x and still not sure if this is still an known issue or not. There seems to be codesandbox docs about using Jest... but no mention of limitations. |
@iDVB I don't think How do we check the version of CodeSandbox from the dashboard btw? |
@dwiyatci You can check the version in any sandbox here: |
@SaraVieira Thank you. :) But what I meant was: how can we tell whether it's CodeSandbox 2.5 or 3.0? 😅 |
Shhhhhit, no idea haha Ask Ives 🤔 |
|
@gautamarora , @gillchristian Are you guys still interested in pursuing this? |
I'd be interested in having the Snapshot Saving feature if possible! Or is it possible already? For example, I was thinking about the potential of the Run any NPM Script feature CodeSandbox Containers, which seems to enable running Jest with the |
@SaraVieira just confirmed my suspicions that this is only possible at the moment with Containers. Is CodeSandbox satisfied with this? Or would you also like to be able to create and update files on non-Container sandboxes? (maybe a whitelisted list of things that can be updated, at least to start with?) |
Also Manual Mocks - those would be super useful. Workaround: At the moment, the closest thing to a workaround that I've found is to use the import { useIt } from "./use-default-export";
import * as myfunc from "./default-export-function";
test("use-default-export-function", () => {
expect(useIt()).toEqual("real");
});
test("use-default-export-function with mock", () => {
myfunc.default = jest.fn(() => "unreal");
expect(useIt()).toEqual("unreal");
}); |
People who came here because this error or similar (like me)
For now you can bypass this issue and use the
|
is this still an issue? I'm getting the same error from 2018 on jest.mock |
is this fixed yet ? |
@stephanepericat i dont think so.. its since 2018 |
Lol just wasted so much time trying to debug it. nvm I guess 😞 |
|
guess this is still a problem 😔 |
Still got this error when running tests.
|
Facing the same issue too |
Hi here, I get the same issue as well https://codesandbox.io/s/modern-morning-md378 Do we have any update on this? |
Apologies if cross-posting issue, but appreciate any work-around or ideas for my issue regarding Jest not working on Static templates: |
Yes, this is still something we want to do, but it's challenging. It's something that we haven't planned in the near-future, but we do want to expand the Jest functionality in the future. I can't tell when we'll have this though. |
This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed. |
It seems like this is still being worked on. |
I'm looking into this one and I have some questions about the jest implementation. Normally, when the Jest global is initialized its created by the jest-runtime and mock/other timer functions are added to the global Jest object. This can be seen here. What's happening in codesandbox is that the jest-runtime is never being initialized - I presume there may be some reason for this. That can be seen here, where jest is actually initialized here with the MockModule class from jest-mock, which populates part of the jest globals into the global space but doesn't add functions like _createJestObjectFor() from jest-runtime. This is why you can use spyOn but not mock - jest-mock actually doesn't declare a mock function until you initialize it with the MockModule.generateFromMetadata<T, Y extends Array>( @CompuIves you're getting tagged just because you seem to be the only maintainer here. There may be someone better who can answer these questions. Sorry about that!
I am trying to get a jest-runtime instance set up in the codesandbox world. I presume there might be issues with this - namely the jest-runtime needs some sort of file/module resolver, which may not play nicely with the codesandbox environment. For everyone who hasn't looked into it - Jest has a lot going on and even I don't completely understand how the Jest runtime works (and its created differently for node/jsdom!). |
Hey guess what .. jest.mock is still NOT a function sigh |
Hey guess what .. jest.mock is still NOT a function sigh |
I'd recommend switching to cloud sandboxes as they can natively run Node tools (including Jest). |
I know cloud sandboxes are recommended, but sinon.useFakeTimers works (just in case anyone was still looking for a solution) |
Creating an issue to discuss future features for Jest integration in CodeSandbox...
Jest in CodeSandbox 2.5 - issue | release
Jest in CodeSandbox 3
Please comment in this issue with more features that should be added to the list.
cc @CompuIves
The text was updated successfully, but these errors were encountered: