You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently took over ownership of an existing codebase.
I am using nock to mock api calls. Some of the service functions I am testing actually use other service functions, which make other api requests.
When I run the test, it fails, because the service function being ran within the service function I am trying to test. I think because the service function that triggers another function that makes an api call too is causing it to fail. I will try to provide some code in theory to illustrate what I mean
`async deleteUser(email) {
let user = await this.getUser(email)
if(!user[0]) {
throw new HttpException(Cant find user email: ${email}, 422)
}
deleteUser function will first get the user, which makes an api call to get a user by their email address, it then returns the user info, which uses the _id in the api response to be used to delete the user.
I looked at chaining and I don't believe that will solve my issue, is there another way?
Obviously refactoring the code will solve this issue, just wondering if there was a feature I missed in the docs.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I recently took over ownership of an existing codebase.
I am using nock to mock api calls. Some of the service functions I am testing actually use other service functions, which make other api requests.
When I run the test, it fails, because the service function being ran within the service function I am trying to test. I think because the service function that triggers another function that makes an api call too is causing it to fail. I will try to provide some code in theory to illustrate what I mean
`async deleteUser(email) {
let user = await this.getUser(email)
if(!user[0]) {
throw new HttpException(
Cant find user email: ${email}
, 422)}
return this.callApi(
v1/users/${user[0]._id}
,'delete')}`
deleteUser function will first get the user, which makes an api call to get a user by their email address, it then returns the user info, which uses the _id in the api response to be used to delete the user.
I looked at chaining and I don't believe that will solve my issue, is there another way?
Obviously refactoring the code will solve this issue, just wondering if there was a feature I missed in the docs.
Beta Was this translation helpful? Give feedback.
All reactions