-
Notifications
You must be signed in to change notification settings - Fork 1.6k
How to test code that depends on RNFetchBlob #212
Comments
I am using Facebook's Jest and I get the same error.
I did try mocking the module, but then I use a constant Thanks. |
I am also experiencing the same error; "TypeError: Cannot read property 'DocumentDir' of undefined" |
@rahimrahman nop, I just include RNFB conditionally based on NODE_ENV |
You have to mock the library. Was using the EX:
|
Agreed with @jnrepo, the key is to mock the objects you are accessing in your code, code work for me
|
I created a file inside the
but i still get an error related to the dir constants: any idea? |
@scerelli try this
|
thx @SoundBlaster but this doesn't solve the error. |
+1,After reinstall, delete app,restart, also failed. edit |
@scerelli mines setup this way in
in
|
@jnrepo look this is the fetch-blob mocked log and this is the jest error: and the line raising this error is:
|
I'm doing all the mocks correctly, AFAIK, but this is the error I get:
Seems to be something with the minified oboe code... any idea how to resolve that one? |
https://github.com/wkh237/react-native-fetch-blob/blob/master/lib/oboe-browser.js#L2701 It indeed is not defined, the line where it is used is the only line where it is mentioned. // cc @wkh237 Is it supposed to be this property? https://developer.mozilla.org/en/docs/Web/API/Window/self |
Does it help if you add this line at the beginning of your program ? global.self = {} |
@jasongaare I think you need this: https://github.com/johanneslumpe/react-native-browser-polyfill It provides the global Okay, it consists of a single line of code, see https://github.com/johanneslumpe/react-native-browser-polyfill/blob/master/polyfills/globalself.js For ref.: RN issue facebook/react-native#1419 |
@wkh237 Actually, I think we need to include this, since it's RNFB code that uses |
Sorry just circling back to this... adding |
As @scerelli I also wanted the mock to happen in a separate place so it can be used by all tests. Placing the following code in
It's a variation of @SoundBlaster solution, just in a global mock file. With that I don't need to import or implicitly mock anything in the test code. |
for me this object works as mock
|
Hi. If someone still get an error /node_modules/redux-persist-filesystem-storage/index.js:5
import RNFetchBlob from 'react-native-fetch-blob'
^^^^^^
SyntaxError: Unexpected token import just add into "jest" section of package.json following option "transformIgnorePatterns": [
"node_modules/(?!react-native|react-navigation)/"
] |
@maldimirov thanks your solution, you save my life ! 💯 |
The |
@maldimirov You are awesome! |
If I want to test a module and that module includes RNFetchBlob, I get this:
react-native-fetch-blob/index.js:6 import { ^^^^^^ SyntaxError: Unexpected token import
That's because babel-core/register don't transpire code within node_modules by default. It I change the config to do it, as it's mentioned here, it crash in this line because NativeModules.RNFetchBlob it's undefined. I get stuck there so I change my es6 include to this dirty piece of code:
Any ideas how to solve this?
This is my test script:
NODE_ENV='test' mocha 'app/**/__tests__/*.js' --compilers js:babel-core/register --require mocha_setup.js
The text was updated successfully, but these errors were encountered: