# How should we mock Sendbird requests to force error cases?

**URL:** <https://community.sendbird.com/t/how-should-we-mock-sendbird-requests-to-force-error-cases/618>\
**Category:** JavaScript\
**Created:** [July 10, 2020, 1:03pm UTC](https://community.sendbird.com/t/how-should-we-mock-sendbird-requests-to-force-error-cases/618 "2020-07-10T13:03:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkay581](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@mkay581](https://community.sendbird.com/u/mkay581)\
**Post date:** [July 10, 2020, 1:03pm UTC](https://community.sendbird.com/t/how-should-we-mock-sendbird-requests-to-force-error-cases/618/1 "2020-07-10T13:03:23Z")

</div>

Hello, we’ve got some good results using Sendbird SDK for our application. However, we’re ready to start testing error scenarios and need to test our code that runs when sendbird API requests fail. There are quite a few scenarios to consider but is there a recommended debugger tool of some sort where we can forcibly fail Sendbird requests locally in the browser?

We’ve tried spinning up a proxy but the sendbird URLs are derived from the user’s API key so it’s not as straightforward as how we would mock our other requests.

Thanks for any information or advice!

---

<div class="post-metadata">

**Author:** ![Woo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/woo/32/125_2.png) [@Woo](https://community.sendbird.com/u/Woo)\
**Post date:** [July 10, 2020, 6:02pm UTC](https://community.sendbird.com/t/how-should-we-mock-sendbird-requests-to-force-error-cases/618/2 "2020-07-10T18:02:51Z")

</div>

@mkay581 If you attempts to use most of methods without using `connect` method, you can simulate fail requests.

---

<div class="post-metadata">

**Author:** ![mkay581](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@mkay581](https://community.sendbird.com/u/mkay581)\
**Post date:** [July 10, 2020, 6:44pm UTC](https://community.sendbird.com/t/how-should-we-mock-sendbird-requests-to-force-error-cases/618/3 "2020-07-10T18:44:47Z")

</div>

Sure but we actually need the connect call. We want to test the errors for other sendbird requests.

---

<div class="post-metadata">

**Author:** ![Tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/tyler/32/810_2.png) [@Tyler](https://community.sendbird.com/u/Tyler)\
**Post date:** [July 10, 2020, 10:19pm UTC](https://community.sendbird.com/t/how-should-we-mock-sendbird-requests-to-force-error-cases/618/4 "2020-07-10T22:19:11Z")

</div>

I wonder if something like [https://mochajs.org/](https://mochajs.org/) would be of use. You could mock the calls that Sendbird is making and return failures.

---

<div class="post-metadata">

**Author:** ![mkay581](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@mkay581](https://community.sendbird.com/u/mkay581)\
**Post date:** [July 13, 2020, 12:13pm UTC](https://community.sendbird.com/t/how-should-we-mock-sendbird-requests-to-force-error-cases/618/5 "2020-07-13T12:13:05Z")

</div>

Oh yes, we’re already using Jest to mock our sendbird wrapper calls in unit tests. But like mentioned in my original post, we need to be able to mock the actual sendbird calls in the browser so that our QA team can test when failures are returned from sendbird calls. We can’t do that by mocking calls in unit tests.

---

<div class="post-metadata">

**Author:** ![Tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/tyler/32/810_2.png) [@Tyler](https://community.sendbird.com/u/Tyler)\
**Post date:** [July 13, 2020, 2:09pm UTC](https://community.sendbird.com/t/how-should-we-mock-sendbird-requests-to-force-error-cases/618/6 "2020-07-13T14:09:19Z")

</div>

Apologizes for that. I misunderstood what you were looking for. I’m trying to do some research to see if there is anything that fits what you’re needing but thus far I’m coming up short. I’ll let you know if I do find anything.

---

<div class="post-metadata">

**Author:** ![mkay581](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@mkay581](https://community.sendbird.com/u/mkay581)\
**Post date:** [July 13, 2020, 2:29pm UTC](https://community.sendbird.com/t/how-should-we-mock-sendbird-requests-to-force-error-cases/618/7 "2020-07-13T14:29:10Z")

</div>

No worries. Yeah we’re already using tools that allow QA team to successfully intercept all other requests in the browser. This problem is scoped to Sendbird requests specifically because the hostname in the request URL to Sendbird’s API is dynamically generated by the user’s session id from the connect call.

---

<div class="post-metadata">

**Author:** ![Vinil\_Chandran](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/vinil_chandran/32/817_2.png) [@Vinil\_Chandran](https://community.sendbird.com/u/Vinil_Chandran)\
**Post date:** [January 13, 2021, 1:17pm UTC](https://community.sendbird.com/t/how-should-we-mock-sendbird-requests-to-force-error-cases/618/8 "2021-01-13T13:17:04Z")

</div>

You can mock like this

every {  
sendBirdSockt.connect()  
} answers {  
Single.error(expectedError)  
}
