soumak77 / firebase-mock

Firebase mock library for writing unit tests
https://soumak77.github.io/firebase-mock
350 stars 96 forks source link

How to check if firestore where function is called with params #150

Open RezaRahmati opened 5 years ago

RezaRahmati commented 5 years ago

I have this code

 async findBotletByTelephonyNumber(number: string): Promise<any> {
            const botletSnapshot = await this.firebaseService.firestore
                .collection('botlet')
                .where(`assignedNumbers.${number}`, '==', true)
                .limit(1)
                .get();
           ... rest of my code

and in my test (with jest) I have below code

  const result = await service.findBotletByTelephonyNumber('123');
    expect(result).toMatchObject({
      assignedNumbers: {
        '123': true
      }
    });
    expect(firebaseService.firestore.collection).toHaveBeenCalled();
    expect(firebaseService.firestore.collection).toHaveBeenCalledWith('botlet');
    expect(firebaseService.firestore.collection().where).toHaveBeenCalled();
    expect(firebaseService.firestore.collection().where).toHaveBeenCalledWith(`assignedNumbers.123`, '==', true);

but I get below error

    expect(jest.fn()).toHaveBeenCalled()

    Expected mock function to have been called, but it was not called.

      129 |     expect(firebaseService.firestore.collection).toHaveBeenCalled();
      130 |     expect(firebaseService.firestore.collection).toHaveBeenCalledWith('botlet');
    > 131 |     expect(firebaseService.firestore.collection().where).toHaveBeenCalled();
          |                                                          ^
      132 |     expect(firebaseService.firestore.collection().where).toHaveBeenCalledWith(`assignedNumbers.123`, '==', true);
      133 |   });
      134 | 

      at Object.it (custom-settings/custom-settings.service.spec.ts:131:58)

What I am doing wrong?