Open simonarcher opened 6 years ago
same as you,
This is working for me:
jest.mock('react-native-cookies', () => ({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest.fn(),
get: () => Promise.resolve(null),
}));
You can't return a normal function since get
returns a promise, and therefore is thenable.
I have forked the repo here: https://github.com/safaiyeh/react-native-cookie-store We can create issues and PRs there to continue the development of the project.
So I believe this has been already brought up in the another issue ( https://github.com/joeferraro/react-native-cookies/issues/16 ), but none of the solutions seems to have resolved the issue for me and looking for additional support if possible.
If I run Jest tests as is, i get the following error
If I modify my tests 'Setup file' with the following
I get the following error
TypeError: CookieManager.get is not a function
I presume this is because 'get' isn't mocked in the file? (This is where things become vague for me)
If I add the 'get' function to the mock, like this
I get the error
TypeError: Cannot read property 'then' of undefined
Anybody able to help identify where Im going wrong here? Not sure how to progress with my tests because of this.
(If this issue is an unecessary duplication, please feel free to close and we can continue the discussion in the other one :) )