Skip to content

Instantly share code, notes, and snippets.

@aVolpe
Created December 7, 2018 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aVolpe/9fb952e4b5d9206d6cb92ef26ce2a17c to your computer and use it in GitHub Desktop.
Save aVolpe/9fb952e4b5d9206d6cb92ef26ce2a17c to your computer and use it in GitHub Desktop.
Simple mocks for ionic
export class MockLoading {
public visible: boolean;
constructor(props: any) {
Object.assign(this, props);
this.visible = false;
}
present() {
this.visible = true;
return Promise.resolve();
}
dismiss() {
this.visible = false;
return Promise.resolve();
}
}
export class MockLoadingController {
public created: MockLoading[];
constructor() {
this.created = [];
}
create(props: any): Promise<any> {
const toRet = new MockLoading(props);
this.created.push(toRet);
return Promise.resolve(toRet);
}
getLast() {
if (!this.created.length) {
return null;
}
return this.created[this.created.length - 1];
}
}
export class MockAlert {
public visible: boolean;
public header: string;
public message: string;
constructor(props: any) {
Object.assign(this, props);
this.visible = false;
}
present() {
this.visible = true;
return Promise.resolve();
}
dismiss() {
this.visible = false;
return Promise.resolve();
}
}
export class MockAlertController {
public created: MockAlert[];
constructor() {
this.created = [];
}
create(props: any): Promise<any> {
const toRet = new MockAlert(props);
this.created.push(toRet);
return Promise.resolve(toRet);
}
getLast() {
if (!this.created.length) {
return null;
}
return this.created[this.created.length - 1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment