sbatson5 / firestore-jest-mock

Jest Helper library for mocking Cloud Firestore
https://www.npmjs.com/package/firestore-jest-mock
177 stars 58 forks source link

Checking for mockUpdate within a datasnapshot forEach #136

Closed kenchambers closed 2 years ago

kenchambers commented 2 years ago

Summary

Is it possible to check if mockUpdate was called on a document that is inside of a dataSnapshot.forEach?


// function i am testing: 

...
dataSnapshot.forEach((doc) => {

doc.update({param: 1})
})
...

But when i test using:

expect(mockCollection).toHaveBeenCalledWith('deals');
expect(mockUpdate).toHaveBeenCalled();

mockCollection is passing, but mockUpdate is not

sbatson5 commented 2 years ago

Unfortunately, that is not currently possible. But it should be! The docs returned by the snapshots right now are just basic objects and not mocks, but I definitely see the value in this

kenchambers commented 2 years ago

@sbatson5 I actually was able to get this to work. It also correctly reads the parameters passed into doc.update

kenchambers commented 2 years ago

thank you for your help