Created
November 4, 2016 04:39
-
-
Save mattste/e034f609878512071bcce17303130b86 to your computer and use it in GitHub Desktop.
Jest Mock Help
This file contains hidden or 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
| // Is there a way for me to mock the fetchNotifications call? | |
| export function fetchNotifications() { | |
| return dispatch => { | |
| dispatch(fetchNotificationsRequest()) | |
| return get('/notifications/self') | |
| .then(json => dispatch(fetchNotificationsSuccess(json))) | |
| .catch(err => dispatch(fetchNotificationsFailure(err))) | |
| } | |
| } | |
| export function updateCreatedNotification(notification) { | |
| return dispatch => { | |
| dispatch(updateCreatedNotificationRequest(notification)) | |
| return put(`/notification/${notification.id}`, notification) | |
| .then((json) => { | |
| // HOW TO MOCK THIS FETCHNOTIFICATIONS CALL? | |
| return dispatch(fetchNotifications()).then(() => { | |
| return dispatch(updateCreatedNotificationSuccess(json)) | |
| }) | |
| }).catch((err) => {throw dispatch(updateCreatedNotificationFailure(err))}) | |
| } | |
| } |
This file contains hidden or 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
| import * as actions from './index' | |
| test('created UPDATE_CREATED_NOTIFICATION_SUCCESS when updating notification request has returned successfully', () => { | |
| actions.fetchNotifications = jest.fn(() => { | |
| console.log('called mock') | |
| return Promise.resolve([]) | |
| }) | |
| actions.updateCreatedNotification(mockNotification) | |
| actions.fetchNotifications.mock.calledOnce() | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment