-
Notifications
You must be signed in to change notification settings - Fork 476
SyntaxError: Unexpected token export using jest #39
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
Comments
Hey @loic-lopez Async Storage is not being transformed by Jest, so in your
|
The error still happening after adding your solution. |
@krizzu thanks for reply and yes I got: ● save
expect(jest.fn()).toHaveBeenCalledWith(expected)
Expected mock function to have been called with:
["something", "{\"x\":1}"]
But it was not called.
34 | test("save", async () => {
35 | await save("something", VALUE_OBJECT)
> 36 | expect(mockSetItem).toHaveBeenCalledWith("something", VALUE_STRING)
| ^
37 | })
38 |
39 | test("saveString", async () => {
at Object.<anonymous>.test (test/tests/storage.test.ts:36:23) as if the mock did not work |
@loic-lopez This is more like Jest question :) You can checkout Jest docs about mocking node_modules libs. Basically, create @vgm8 Anything particular that could help me figuring this out? |
@krizzu the mock is on top of my |
@krizzu your solution was not working because i had some errors in the jest configuration. After I fixed it works fine, thank you! |
@vgm8 Thanks great! Would you mind sharing your solution, for future references? |
@krizzu As you can see above, the mock is being running before my tests. |
I have same issue. @loic-lopez |
Sure @krizzu! As you said in your comment I've created
An then in my tests I just import and mock
|
@NemanjaManot Do you have resolved your issue? |
@loic-lopez not yet. |
getting |
@opiruyan Thanks! This is from latest release (1.2.2), where we notice devs to link the library in order to use it. I'll try to come up with custom mocks + docs to help people test this library on the weekend. thanks. |
@vgm8, thanks for your mock implementation, it saved me time and I can confirm that it works. |
Hey everyone participating in this issue, I've created a PR with mocks and jest integration guide, so I hope future issues with testing would be resolved. Let me know what you think! thanks. #edit fixed link |
@krizzu thanks but your link seems to be broken. |
Updated the lib but I din't get the @react-native-community/async-storage/jest/async-storage-mock The jest folder doesn't seem to be included in the dist of react-native-async-storage?
|
Oh, I thought it was since it was in the docs. |
looks like RN took care of transformIgnorePatters-part of the issue |
Released in v1.3.0, please check it out 🙏 |
@krizzu I'm still have issues, are you aware of this problem:
The solution here was switching to a different mocking package but I'm hoping that's not necessary. |
turns out I fixed it by using @vgm8's mock above So maybe there's a syntax error in your official one that Jest doesn't like. |
@krizzu should the problem mentioned above be fixed in the official mock? I'm getting the same thing. |
@redreceipt @janpe We use this setup on the repo's example app and it's fine. Seems like your setup might be missing a proper flow handling. |
We see the same |
It seems like the issue comes from the lack of transformation by Jest. We have a docs on how to fix this here. Let me know if it worked. |
@krizzu, no help, at least, with the "Jest setup file" option. So to be clear, I've followed the instructions to include 2 lines in my setup file, AND included the transformIgnorePatterns you suggested. [EDIT] Ah, right, but I'm also using RN 0.59.10, so since that ignore pattern is already part of 0.59.4, my understanding is that this should be unnecessary. [EDIT2] I'd swear this has something to do with Typescript not being recognized. Does that help? [EDIT3] Ok, so FLOW, not TypeScript, and I seem to have determined, "No, it's not a tumor!" (i.e. that's not the problem) BTW, sorry for the constant EDITs -- hopefully this is clearer than replying to myself a million times in separate posts. [EDIT4] Some progress. So creating
With this setup, tests pass. But if instead of copying the contents I just have the As far as I understand things, which at this point is not all that well, this would sure seem to indicate that my node_modules files are, in fact, not being transpiled by Babel before being passed on to Jest. |
@frozenzia did you find the solution for this? im having the same... |
@cinder92 , no, actually. I got fed up / out-of-time trying to figure out what was going on with the mock included in the package, and just went with a modified version of @vgm8's mock. We only needed setItem, getItem, and removeItem, AND we have some airBnB eslint rules in place so that the end result was that
|
@frozenzia How does your setup looks like? Is it monorepo by any chance?
Looks like an issue with |
My project neither contains Flow nor TypeScript and I too get the ● Test suite failed to runmponent.test.js
/Users/jan/dev/my-app/node_modules/@react-native-communit
y/async-storage/jest/async-storage-mock.js:
6
type KeysType = Array<string>;
^^^^^^^^
SyntaxError: Unexpected identifier It feels like |
It's also possible to exclude this file in .flowconfig by adding |
I have fixed the error
using those instructions in my project: https://github.com/react-native-community/async-storage/blob/LEGACY/docs/Jest-integration.md#syntaxerror-unexpected-token-export-in-async-storagelibindexjs |
|
Uh oh!
There was an error while loading. Please reload this page.
Current behavior
Repro steps
import @react-native-community/async-storage
and test with jest.Environment
The text was updated successfully, but these errors were encountered: