diff --git a/src/angular/toast-controller.spec.ts b/src/angular/toast-controller.spec.ts new file mode 100644 index 0000000..0cf6fb3 --- /dev/null +++ b/src/angular/toast-controller.spec.ts @@ -0,0 +1,36 @@ +import { ToastControllerMock } from './toast-controller'; +import { ToastMock } from './toast'; + +describe('ToastController', () => { + let classUnderTest: any; + + beforeEach(() => { + classUnderTest = new ToastControllerMock(); + }); + + it('should be defined', () => { + expect(classUnderTest).toBeDefined(); + }); + + describe('create', () => { + it('should exist', () => { + expect(classUnderTest.create).toBeDefined(); + }); + + it('should return a Toast', () => { + let result = classUnderTest.create(); + + expect(result).toBeDefined(); + expect(result.present).toBeDefined(); + }); + + it('should return provided Toast', () => { + let toast = new ToastMock(); + classUnderTest = new ToastControllerMock(toast); + + let result = classUnderTest.create(); + + expect(result).toBe(toast); + }); + }); +}); diff --git a/src/angular/toast-controller.ts b/src/angular/toast-controller.ts index d80d344..24630a1 100644 --- a/src/angular/toast-controller.ts +++ b/src/angular/toast-controller.ts @@ -1,11 +1,17 @@ -import {ToastMock} from './toast'; +import deprecated from 'deprecated-decorator'; +import { BaseMock } from '../base.mock'; +import { ToastMock } from './toast'; -export class ToastControllerMock { - public static instance(toast?: ToastMock): any { +const METHODS = ['create']; - let instance = jasmine.createSpyObj('ToastController', ['create']); - instance.create.and.returnValue(toast || ToastMock.instance()); +export class ToastControllerMock extends BaseMock { + constructor(toast?: ToastMock) { + super('ToastController', METHODS); + this.spyObj.create.and.returnValue(toast || new ToastMock()); + } - return instance; + @deprecated('new ToastControllerMock()') + public static instance(toast?: ToastMock): any { + return new ToastControllerMock(toast); } }