Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49332

Injecting mock providers only for dev mode

$
0
0

@arctican wrote:

Hello.

I’ve created a couple of mock classes for testing in the browser. When testing on a device, I manually remove these from the providers list before the build. I now want to automatically include or remove them based on the --prod flag.

I have tried various methods, from webpack config, to environment variables, to custom services. In other parts of the app, I use isDevMode() as a quick getter to change some variables. The trouble is that isDevMode() can’t be called before enableProdMode() which appears to be after the main module is set up.

I would like to conditionally add an array of mock providers to the provider list such as:

const mockProviders = [
    { provide: Camera, useClass: CameraMock },
    { provide: Geolocation, useClass: LocationMock },
];

@NgModule({
    providers: [
    	commonProviders,
    	isDevMode() ? mockProviders : []
    ],
    ....

Is there a simple way to do this?

Cheers

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>