-
Notifications
You must be signed in to change notification settings - Fork 90
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 test on function that's not exported #183
Comments
in import file from './file';
const foo = file.__get__('foo');
const returnValueOfFoo = foo(params) |
I'm currently not able to get past the
However, I'm getting the following error when I
Note:
|
@ryanhomer try: {
"presets": [
"es2015",
"stage-0"
],
"env": {
"test": {
"plugins": [
"istanbul",
"babel-plugin-rewire"
]
}
}
} |
Looks like It took about 3 seconds longer than before to throw the error but I'm still getting the same error. Any further suggestions are appreciated. Thanks. |
@ryanhomer did you add istanbul and switch your rewire to babel-install-rewire? |
Yes, I copied/pasted the |
@ryanhomer oh it looks like it doesn't like your use of |
Oops nevermind, that was crazy talk. I can only get it to work by editing my local version of |
Is it incompatible with jest-hoist? I get a |
I'm having the same issue like @ryanhomer. When adding
|
Issue is still happening :( |
same error in react native project.
|
Try out this solution: #109 (comment). I was able to get past the invalid variable access issue by switching from Explicit imports seem like a better idea to me anyways :) |
If anyone else is still having this problem: I incorporated @sarahatwork's local edit into an npm pretest:
That way it still works even if babel-plugin-jest-hoist gets reinstalled. Even with that, I also needed to follow some of the advice in the solution referenced by @jvivs and make sure there was a reference in my module to anything in it I wanted to test. |
same error here with react native. |
@ryanhomer I was able to reproduce your error about This example should work: file.js:
file.tests.js:
|
A solution for TypeScript is here: https://stackoverflow.com/questions/54697062/test-or-mock-a-not-exported-function-with-jest-using-typescript. |
Is there any solution to how can we mock Function without exporting and passing the test data for that to complete our test code? Also, can you guys help me how to pass data to the useState for the test code? |
I'm trying to do unit tests using Jest on a function that is not exported. I'm unable to use Rewire because I'm in a React Native environment with babel. I only want to get the function but I can't figure this out from the documentation. For example, let's say I have a file
file.js
that has a functionfoo
. How do I reference this function from my test file.file.js:
file.tests.js:
Thanks!
The text was updated successfully, but these errors were encountered: