Hello everyone,
I’m trying to figure out how to mock platform property “backButton” to coverage inside this.platform.backButton.subscribeWithPriority(10, () => {}).
Example of test.component.ts:
import { Platform } from '@ionic/angular';
constructor(private platform: Platform) {}
public disableBackButtonAndroid(){
this.platform.backButton.subscribeWithPriority(10, () => {
return;
});
}
Example of test.component.spec.ts:
platformMock = {
backButton: {
subscribeWithPriority: jest.fn().mockReturnValue(of()),
},
};
beforeEach(async () => {
TestBed.configureTestingModule({
declarations: [CompartilhamentoItemComponent],
providers: [
provideMockStore({ initialState }),
{
provide: Platform,
useValue: platformMock
},
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
});
Has anyone get success in coverage any example of a property of Platform?
Versions that I’m using:
Angular: 10;
Ionic: v5;
Unit testing framework: Jest.