#How to mock the twilioClient in my Authentication Service with jest
16 messages · Page 1 of 1 (latest)
when i run the test, i get the following error.. I want to mock this twilioClient and all its functions. Any help appreciated been stuck on this for a while!
How to mock the twilioClient in my Authentication Service with jest
Because you use new Twilio() you'd have to mock the twilio package using jest.mock. I'd rather suggest making that a provider so you can mock the provided object rather than the constructor
thanks @civic narwhal
to make it a provider i would have to setup a twilioModule right?
Not necessarily. If you plan to use it in multiple locations I would though
what would be the other way, if i dont make it a module?
Just add it to the current module's providers
Like new TwilioClient()
{
provide: 'TWILIO_CLIENT',
inject: [TWILIO_CLIENT_OPTIONS_TOKEN],
useFactory: (options) => new Twilio(options)m
}
Assuming that the options have a dedicated token
An injection token. If they don't you could just inject the ConfigService instead and pull the values from there
ok makes sense.. this would be easier to test then!