typescript - Ionic + Jasmine + Tslint - Property 'and' does not exist on type -
everybody. building ionic app on boilerplate. right now, building tests specific page , using jasmine mock providers , set expected behavior methods. that's how beforeeach() method looks looks like:
beforeeach(() => { mockloadingcontroller = jasmine.createspyobj('modalcontroller', ['create', 'present', 'dismiss']); mockloadingcontroller.create.and.returnvalue(mockloadingcontroller); mockmodalcontroller = jasmine.createspyobj('loadingcontroller', ['create', 'present', 'ondiddismiss', 'dismiss']); mockmodalcontroller.create.and.returnvalue(mockmodalcontroller); mockgeolocation = jasmine.createspyobj('geolocation', ['getcurrentposition']); mockgeolocation.getcurrentposition.and.callfake(( ) => { return {then: ( ) => { }}; }); mockevents = jasmine.createspyobj('events', ['publish', 'subscribe']); testbed.configuretestingmodule({ schemas: [custom_elements_schema], providers: [ { provide: navcontroller, usevalue: mocknavcontroller }, { provide: loadingcontroller, usevalue: mockloadingcontroller }, { provide: modalcontroller, usevalue: mockmodalcontroller }, { provide: geolocation, usevalue: mockgeolocation }, { provide: events, usevalue: mockevents }, locationpage, ], }, ); } );
the problem starts when define promise return getcurrentposition method:
mockgeolocation.getcurrentposition.and.callfake(( ) => { return {then: ( ) => { }}; });
i using tslint while testing and, gives me following error
error in [at-loader] ./src/pages/location/location.page.spec.ts:24:40 ts2339: property 'and' not exist on type '(options?: geolocationoptions) => promise<geoposition>'.
the question is: how can overcame matter tslint not complain code anymore?
problem solved! forgot detail way declaring variables:
describe('location page', () => { let mockloadingcontroller: any; let mockmodalcontroller: any; let mockgeolocation: geolocation; let mockevents: events; beforeeach(() => { //rest of code here
as can see, defined type mockgeolocation variable , did set others any. setting variables works jasmine , not generate error in tslint.
so correct code works this:
describe('location page', () => { let mockloadingcontroller: any; let mockmodalcontroller: any; let mockgeolocation: any; let mockevents: any; beforeeach(() => {
Comments
Post a Comment