ionic-native-mocks icon indicating copy to clipboard operation
ionic-native-mocks copied to clipboard

[DOC] Add prod / dev switch scenario

Open vogloblinsky opened this issue 7 years ago • 3 comments

Hi,

Thanks for these useful mocks.

Could you add in the main README an explanation about how we can disable mock in production mode ?

//AOT trick
let checkDevMode = false;
if (isDevMode()) {
  checkDevMode = true;
}
const CameraConfiguration = (checkDevMode) ? { provide: Camera, useClass: CameraMock } : Camera;

providers: [
    ...,
    CameraConfiguration,
    ...
]

vogloblinsky avatar Jul 08 '18 21:07 vogloblinsky

I think this approach is better. You don't have to change it every time you build your app:

const isBrowser = document.URL.includes(‘https://’) || document.URL.includes(‘http://’);/*document.URL.startsWith(‘http’);

and then a bit lower in the provides :

(isBrowser ? {provide : Camera, useClass : CameraMock} : Camera),
(isBrowser ? {provide : ImagePicker, useClass : ImagePickerMock} : ImagePicker),
(isBrowser ? {provide : Geolocation, useClass : GeolocationMock} : Geolocation),

asofyan avatar Jul 12 '18 02:07 asofyan

Thanks. I will add this to the Read Me shortly.

chrisgriffith avatar Jul 12 '18 16:07 chrisgriffith

const isBrowser = document.URL.includes(‘https://’) || document.URL.includes(‘http://’);/*document.URL.startsWith(‘http’);

Your approach doesnt work i logged this and it always returned true . and ionic seems to be running in the localhost in a mobile device

sebinpj avatar May 09 '19 12:05 sebinpj