Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RezaRahmati opened this issue Aug 1, 2019 · 0 comments
Open

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

RezaRahmati opened this issue Aug 1, 2019 · 0 comments

Comments

@RezaRahmati
Copy link

RezaRahmati commented Aug 1, 2019

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?

@RezaRahmati RezaRahmati changed the title How to check if firestore where condition is called How to check if firestore where function is called with params Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant