FYI.. I mock the platform as true in my mock file. Here I'm getting the platform as cordova.
I'm getting below error when I excute the above test case.
TypeError: undefined is not an object (evaluating 'window['plugins'].appPreferences') in config/karma-shim.js (line 29367)
Can anyone please let me know how to mock this plugin.
My mock file:
export class MockPlatformWithCordova {
public ready(): any {
return new Promise((resolve: Function) => {
resolve();
});
}
public is(name: string){
if (name === 'cordova')
return true;
return true;
}
}
Please specify your environment
Plugin version:
[ ] released version: _____
[x] repository master
Toolchain:
[x] Cordova cli
[ ] Phonegap cli
[ ] Phonegap cloud
[x] Ionic
[ ] Other: _____
Platforms affected:
[ ] Android
[x] iOS/macOS
[ ] LocalStorage fallback for browser and blackberry
[ ] Windows and Windows Phone 8.1 and later
[ ] Windows Phone 8 and earlier (deprecated)
What the scope of your problem:
[ ] General functionality (store/fetch/remove/clearAll)
Issue:
I need to write test cases for this plugin in my project. Below is the way I tried in my project but I'm getting the error.
ts file: save(){
if (this.platform.is('cordova')){ var prefs = window['plugins'].appPreferences; prefs.store (null, this.onPrefStoreError, 'serverUrl', this._settings.serverUrl); prefs.store (null, this.onPrefStoreError, 'useProxy', this._settings.useProxy); }
localStorage['settings'] = JSON.stringify(this._settings); console.log('saved settings');
}
Spec file: it('call save', inject([SettingsService,Platform], (settingsService: SettingsService, platform: Platform) => {
settingsService.save(); }); });
FYI.. I mock the platform as true in my mock file. Here I'm getting the platform as cordova. I'm getting below error when I excute the above test case. TypeError: undefined is not an object (evaluating 'window['plugins'].appPreferences') in config/karma-shim.js (line 29367)
Can anyone please let me know how to mock this plugin.
My mock file: export class MockPlatformWithCordova { public ready(): any { return new Promise((resolve: Function) => { resolve(); }); }
}
Please specify your environment
Plugin version:
Toolchain:
Platforms affected:
What the scope of your problem: