You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, can you spot what's wrong with the setup below that's preventing my second mock function from being called?
Code to be tested (tasks.js):
exportconstdeleteFlaggedCandidateAccounts=async(app)=>{consttimer=moment()constusers=app.service('users')constevents=app.service('events')constusersForDeletion=awaitfindFlaggedCandidates({ events, users })if(usersForDeletion.length>0){constsubCollectionNames=['jobActivities','interviews','matches','offers']constsubCollections=subCollectionNames.map(serviceName=>{return{name: serviceName,service: app.service(serviceName)}})constprofiles=app.service('profiles')constimages=app.service('images')constvideos=app.service('videos')usersForDeletion.forEach(({_id: id, defaultObjects })=>{defaultObjects.forEach(({target: {_id: profileId}, type })=>{if(type===CANDIDATE_DEFAULT_OBJECT_TYPE){logger.debug(`Redacting data & deleting account details for user: ${id} with profileId: ${profileId}`)deleteCandidateAccount({ users, profiles, images, videos, subCollections, id, profileId })}})})}}
My jest test:
import{CANDIDATE_DEFAULT_OBJECT_TYPE}from'./tasks'importTasksModulefrom'./tasks'import{deleteFlaggedCandidateAccounts,__RewireAPI__as_TasksRewireAPI}from'./tasks'constmockApp={service: jest.fn()}constmockFlaggedUsers=[{_id: 'userID101',defaultObjects: [{target: {_id: 'profileID101'},type: CANDIDATE_DEFAULT_OBJECT_TYPE}]}]describe('deleteCandidateAccounts',()=>{it('should just bloody work',async()=>{constmockDelete=jest.fn()TasksModule.__Rewire__('findFlaggedCandidates',()=>mockFlaggedUsers)TasksModule.__Rewire__('deleteCandidateAccount',()=>mockDelete)deleteFlaggedCandidateAccounts(mockApp)expect(mockApp.service).toHaveBeenCalled()// PASSexpect(mockDelete).toHaveBeenCalled()// FAIL :( no idea why__rewire_reset_all__()})})
If I set the findFlaggedCandidates as a constant in the method so that I'm only mocking deleteCandidateAccount then the test passes fine hence my suspicion and the issue title.
Any help/pointers much appreciated!
The text was updated successfully, but these errors were encountered:
Hello, can you spot what's wrong with the setup below that's preventing my second mock function from being called?
Code to be tested (tasks.js):
My jest test:
If I set the
findFlaggedCandidates
as a constant in the method so that I'm only mockingdeleteCandidateAccount
then the test passes fine hence my suspicion and the issue title.Any help/pointers much appreciated!
The text was updated successfully, but these errors were encountered: