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
fix(): export setEnv
for handling env edge cases
#8888
Conversation
Build Stats
|
setEnv
setEnv
for Jest interoperability
Merged and now i ll push beta5. |
setEnv
for Jest interoperabilitysetEnv
for handling env edge cases
@asturur apparently this issue wasn't related to jest, at least not to the latest version. |
It proves without doubt that it is possible to use fabric with jest (>=29), importing behavior works as expected. |
In the website I can make this into a guide about using fabric and jest for tests. |
Motivation
Working on an app using CRA (create-react-app, complete 💩 and abandoned as well) that uses jest for testing.
After migrating to v6 got an error related to jsdom, CRA is to blame (can't reproduce with a simple jest example, see below).
What happened is that for some reason the CRA jest config now imports the node entry point whereas before (v5) fabric thought it was running in the browser because of jest mocking window/document.
Seems to be a jsdom mismatch of versions. Didn't look into it. And is an edge case we should not cater for.
Setting env fixes it because it exposes the mocked window/document to fabric.
Description
expose
setEnv
with a clear comment on usage.Changes
Gist
If you want to setup jest in order to test your fabric project (in node or in a mocked browser environment) follow this:
Testing fabric with jest
If for some sad reason you are using CRA or encountering the error above then try the following:
If you wish to mock fabric (no real reason to do that) you can add these lines to your mocked module
__mocks__/fabric.ts
In Action