mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-21 00:23:00 +08:00
tests(): add test to verify new way of creating classes
This commit is contained in:
parent
146c823f2a
commit
238e2ab26c
69
src/@ionic-native/core/ionic-native-plugin.spec.ts
Normal file
69
src/@ionic-native/core/ionic-native-plugin.spec.ts
Normal file
@ -0,0 +1,69 @@
|
||||
// This is to verify that new (FileTransfer.getPlugin)() works
|
||||
|
||||
import { Plugin, CordovaInstance } from './decorators';
|
||||
import { checkAvailability } from './plugin';
|
||||
import { IonicNativePlugin } from './ionic-native-plugin';
|
||||
|
||||
class FT {
|
||||
hello(): string {
|
||||
return 'world';
|
||||
}
|
||||
}
|
||||
|
||||
(window as any).FileTransfer = () => new FT();
|
||||
|
||||
@Plugin({
|
||||
plugin: 'cordova-plugin-file-transfer',
|
||||
pluginRef: 'FileTransfer',
|
||||
repo: '',
|
||||
pluginName: 'FileTransfer'
|
||||
})
|
||||
export class FileTransfer extends IonicNativePlugin {
|
||||
create(): FileTransferObject {
|
||||
let instance: any;
|
||||
if (checkAvailability(FileTransfer.getPluginRef(), null, FileTransfer.getPluginName()) === true) {
|
||||
instance = new (FileTransfer.getPlugin())();
|
||||
}
|
||||
return new FileTransferObject(instance);
|
||||
}
|
||||
}
|
||||
|
||||
export class FileTransferObject {
|
||||
|
||||
constructor(public _objectInstance: any) {
|
||||
console.info('Creating a new FileTransferObject with instance: ', _objectInstance);
|
||||
}
|
||||
|
||||
@CordovaInstance({ sync: true })
|
||||
hello(): string { return; }
|
||||
|
||||
}
|
||||
|
||||
describe('Mock FileTransfer Plugin', () => {
|
||||
|
||||
let plugin: FileTransfer,
|
||||
instance: FileTransferObject;
|
||||
|
||||
beforeAll(() => {
|
||||
plugin = new FileTransfer();
|
||||
instance = plugin.create();
|
||||
});
|
||||
|
||||
it('should create a new FileTransfer plugin instance', () => {
|
||||
expect(plugin instanceof FileTransfer).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should create new FileTransferObject instance', () => {
|
||||
expect(instance instanceof FileTransferObject).toBeTruthy();
|
||||
});
|
||||
|
||||
it('FileTransferObject instance should have _objectInstance property', () => {
|
||||
expect(instance._objectInstance).toBeDefined();
|
||||
});
|
||||
|
||||
it('FileTransferObject.hello should return world', () => {
|
||||
console.info('instance hello is', instance.hello());
|
||||
expect(instance.hello()).toEqual('world');
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user