forcedotcom/SalesforceMobileSDK-ReactNative

Issue with jest

manishprakharan067 opened this issue · 8 comments

I am using Jest framework to write test cases.
I am not getting coverage when I try to write jest for my file
then() => {} block does not get's called and there is no coverage

image

I get error when i mock react-native-force
and i use code

jest.mock('react-native-force', () => { forceUtil: jest.fn() mobilesync: jest.fn() net: jest.fn() oauth: jest.fn() smartstore: jest.fn() });

I am not able to mock
forceUtil, mobilesync, net, oauth, smartstore
from react-native-force

I get error

TypeError: Cannot read properties of undefined (reading 'forceUtil')

image

Please provide the solution how can I mock react-native-force and it's functionalities
and how can i use Jest to get the full coverage.

Are you first doing

import {forceUtil} from 'react-native-force';

image

This is my StoreManager.js file

image

image

image

In The above Image then() => {} block doesn’t gets called.

i get error When I write the below code in JestSetup.js file

image

hi @wmathurin can you please look into

We are not expert in Jest. Have you tried getting help on https://github.com/facebook/jest ?

@wmathurin Yes I have tried But not able to mock react-native-force
You guys don’t have documentation on how to mock react-native-force ?

We don't have documentation specifically for that. But the entire library is open source (and quite small).

Closing this thread now since it is not about a Mobile SDK bug or enhancement.