Comments (6)
How can I mock twillo module for testing?
The same here
from nestjs-twilio.
@rcaceiro @qamalyanaren We had the same question about the testing here #10, if you need a more concrete example, please provide me with context so that I can help you
from nestjs-twilio.
@rejvban I want to mock this function in the service
https://user-images.githubusercontent.com/18355408/128837763-cdcc6a55-6aef-4ebf-91f4-f1a4ac0c920e.png
from nestjs-twilio.
@qamalyanaren Since this has become a rather reacurring question, I'm going to try to explain how it's tested in the library itself. But I think that this is more of a general testing question. File for reference!
Since I don't see the whole context, I'm going to go through the example with the assumption that you only want to test the twilio module https://github.com/rejvban/nestjs-twilio/blob/e846f88fd330b0531e2ed0414b77717ed4af6fbc/lib/__tests__/twilio.decorators.test.ts#L27-L37
First I created the mock injectable service containing the injected twilio client and then provided it to the testing module which is properly initializing the TwilioModule
in order for the service to work. You should also be able to use your written service, just be cautious when initializing the module.
Then, from the test module, you can access the appropriate service, in this case, its client (TwilioClient
) and a whole bunch of methods that that client provides.
I can vouch that this approach works, considering that we have automated tests that send an SMS to my personal phone each time the test passes each time that there's a change on the master
branch.
Also sorry for the late reply, been really busy at work, hope I could help!
from nestjs-twilio.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from nestjs-twilio.
hi, can I know how can I mock the injected service ?, I don't want it to call the real client, I want to mock the injected dependency, with the above approach I cant override the function from the client. When I execute my test, I am getting this error
The requested resource /2010-04-01/Accounts/ACSid/Messages.json was not found
I tried to mock the client using the following
{
provide: InjectableService,
useValue: {
client: {
messages: { create: jest.fn().mockResolvedValue(true) }
}
}
But still receiving the above error.
from nestjs-twilio.
Related Issues (20)
- testing HOT 1
- cant resolve dependency tree HOT 4
- Cannot install with nest v8 HOT 2
- Constructor injection gives the following error HOT 4
- does not work with sub-module HOT 4
- Nest 9.X support? HOT 6
- Is there way to disable or postpone client authorization? HOT 4
- Update the dependencies HOT 1
- Property 'forRoot' does not exist on type 'TwilioModule' HOT 4
- Configurable module import dependency resolution error HOT 3
- Property 'forRoot' does not exist on type 'typeof TwilioModule' HOT 4
- Package JSON Bug
- The 4.1.0 was not published in NPM. HOT 1
- How can I generate a client token using nestjs-twilio? HOT 3
- Twilio itself should be a peer dependency
- Configurable module import dependency resolution error HOT 4
- Can I register multiple Twillio accounts in one app? HOT 1
- ERROR [ExceptionHandler] Nest can't resolve dependencies of the TwilioService HOT 1
- Publish action not running as intended HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nestjs-twilio.