Context
We are creating a library that makes an API (HTTP) request to a 3rd party.
During testing we have written mock versions of the functions that make external requests so that we can test the other functionality in isolation.
Question
Should we export the mock version of the functions in the library so that the application using the library can use the mocks in its' own tests to avoid duplicating the mocks?
e.g: (pseudocode)
if (ENV=="test") {
return MockImplementation
}
else {
return RealImplementation
}
Is this considered an "anti-pattern" or a "best-practice" when creating a library?
Note: not looking for opinions or flame-war, just some clarity on what to do in practice.
We've tried googling for this, but no relevant result surfaced ... hence the direct question.
If this is not the appropriate place to ask this type of question, where is?
Any insight much appreciated! Thanks!
Additional Detail
We aren't using a mocking library/framework. Our mocks simply return sample response. The application that is consuming the library we are building has to mock the same request because the API in question (Google!) does not have a "test" endpoint. I'm trying not to be too specific so the question is general. The library we've created is intended for general use but we are using it in our own App/project where we are having to duplicate the mocks of the library.