Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): add jest tests and mock file for library users (#140)
* feat: setup jest script * feat: create jest.config file * feat: create mocks to appevents and params * feat: added jest to eslint * feat: added test example inside readme * feat: added spyOn example to Readme * feat: added jest folder to package/json
- Loading branch information
Showing
5 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: 'react-native', | ||
setupFiles: ['./jest/setup.js'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const nonMocked = require('../../lib/commonjs'); | ||
|
||
export const mockAppEvents = { | ||
AchievedLevel: 'fb_mobile_level_achieved', | ||
AdClick: 'AdClick', | ||
AdImpression: 'AdImpression', | ||
AddedPaymentInfo: 'fb_mobile_add_payment_info', | ||
AddedToCart: 'fb_mobile_add_to_cart', | ||
AddedToWishlist: 'fb_mobile_add_to_wishlist', | ||
CompletedRegistration: 'fb_mobile_complete_registration', | ||
CompletedTutorial: 'fb_mobile_tutorial_completion', | ||
Contact: 'Contact', | ||
CustomizeProduct: 'CustomizeProduct', | ||
Donate: 'Donate', | ||
FindLocation: 'FindLocation', | ||
InitiatedCheckout: 'fb_mobile_initiated_checkout', | ||
Purchased: 'fb_mobile_purchase', | ||
Rated: 'fb_mobile_rate', | ||
Schedule: 'Schedule', | ||
Searched: 'fb_mobile_search', | ||
SpentCredits: 'fb_mobile_spent_credits', | ||
StartTrial: 'StartTrial', | ||
SubmitApplication: 'SubmitApplication', | ||
Subscribe: 'Subscribe', | ||
UnlockedAchievement: 'fb_mobile_achievement_unlocked', | ||
ViewedContent: 'fb_mobile_content_view', | ||
}; | ||
|
||
export const mockAppEventParams = { | ||
AddType: 'ad_type', | ||
Content: 'fb_content', | ||
ContentID: 'fb_content_id', | ||
ContentType: 'fb_content_type', | ||
Currency: 'fb_currency', | ||
Description: 'fb_description', | ||
Level: 'fb_level', | ||
MaxRatingValue: 'fb_max_rating_value', | ||
NumItems: 'fb_num_items', | ||
OrderId: 'fb_order_id', | ||
PaymentInfoAvailable: 'fb_payment_info_available', | ||
RegistrationMethod: 'fb_registration_method', | ||
SearchString: 'fb_search_string', | ||
Success: 'fb_success', | ||
ValueNo: '0', | ||
ValueYes: '1', | ||
}; | ||
|
||
export default { | ||
AppEventsLogger: { | ||
logEvent: jest.fn(), | ||
logPurchase: jest.fn(), | ||
setUserID: jest.fn(), | ||
AppEventParams: mockAppEventParams, | ||
AppEvents: mockAppEvents, | ||
}, | ||
LoginManager: { | ||
logInWithPermissions: jest.fn(), | ||
}, | ||
Settings: { | ||
initializeSDK: jest.fn(), | ||
}, | ||
LoginButton: nonMocked.LoginButton, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* eslint-env jest */ | ||
|
||
jest.mock('../src', () => require('./mocks').default); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters