Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
How to abstract environmental JS class implementations

I have an abstraction of an adapter. Through an environmeht variable I control which implementation is used. I am not satisfied with this approach, since the mock variant is imported in production code. I would like to have something like in Symfony, where implementation of abstractions can be defined in environmental service configurations.

Currently I have following abstraction:

import HttpERPAdapter from "./HttpERPAdapter";
import MockERPAdapter from "./MockERPAdapter"; // todo, find an abstraction solution to not deploy this in production
import httpClient from "common/HttpClient";

const create = () => {
    if (process.env.REACT_APP_ERP_API_URL === 'mock') {
        return new MockERPAdapter();
    }
    return new HttpERPAdapter(httpClient);
}

const erpAdapter = create();
export default erpAdapter;
  • The mock variant: Mainly used when developing GUI when I have not to rely on real api data, for faster development.
  • The productive variant: For for developing with real api data, and for the productive build

I am sure that a compilation in a production build will contain the mock class, this is also what I want to prevent.
In general I want that the productive code knows nothing about mocks/fake-services.

Any ideas on how to separate the mock implementation from the productive code?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!