how to test the below code in angular jasmine

fetchTotalProjetsCount() { return new Promise((resolve, reject) => { this.http.get(environment.ENV_URL + Constant.constats.endpoints.TOTAL_PROJECT_COUNT).subscribe((res: ResponseAPI) => { Iif (res?.statusCode === 200) { resolve(res) } reject() }) }).catch(err => console.error(err)) } How to test the above code in angular jasmine
9 Replies
Coder_Carl
Coder_Carl3y ago
@Muhd Boy Khal Gaming I think you are looking at this the wrong way. the api that you are sending your GET request to should have it's own tests. so you dont need to test the value of what you get back. what you should be doing is checking that fetchTotalProjectsCount is returning a promise
Muhammed Khal
Muhammed Khal3y ago
How to test it Can you please send me the test cases for it @Coder_Carl
Coder_Carl
Coder_Carl3y ago
I would consider where it is being invoked. It is only wrapping a GET request at present. in the function that is actually invoking the fetchTotalProjectsCount I would: - create a stub/mock with sinon - test that the function was being invoked. there isnt anything else to test
Muhammed Khal
Muhammed Khal3y ago
Can you please send me the code I'm completely new to it @Coder_Carl
Coder_Carl
Coder_Carl3y ago
sorry I think you should be reading the documentation and writing some tests first before asking for help
Muhammed Khal
Muhammed Khal3y ago
Yes but I need to submit it now Please brother So I can understand by seeing your cods Code
Muhammed Khal
Muhammed Khal3y ago
Coder_Carl
Coder_Carl3y ago
sorry Muhd, this is a great place to ask for help on information but we are not here to do homework that you didnt do
Muhammed Khal
Muhammed Khal3y ago
What I need to add there
Want results from more Discord servers?
Add your server