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
@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
How to test it
Can you please send me the test cases for it @Coder_Carl
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
Can you please send me the code
I'm completely new to it
@Coder_Carl
sorry I think you should be reading the documentation and writing some tests first before asking for help
Yes but I need to submit it now
Please brother
So I can understand by seeing your cods
Code
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
What I need to add there