Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to write jasmine test cases for plugin #125

Open
5 of 16 tasks
maruthi-menlo opened this issue Mar 22, 2017 · 0 comments
Open
5 of 16 tasks

How to write jasmine test cases for plugin #125

maruthi-menlo opened this issue Mar 22, 2017 · 0 comments

Comments

@maruthi-menlo
Copy link

maruthi-menlo commented Mar 22, 2017

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();
});
}

public is(name: string){
	if (name === 'cordova')
		return true;
	return true;
}

}

Please specify your environment

Plugin version:

  • released version: _____
  • repository master

Toolchain:

  • Cordova cli
  • Phonegap cli
  • Phonegap cloud
  • Ionic
  • Other: _____

Platforms affected:

  • Android
  • 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)
  • Suites
  • Cloud synchronization and events
  • Preferences pane generation and display
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant