У меня есть приложение Electron, которое использует Angular (8) в качестве внешнего интерфейса. Я пытаюсь реализовать модульное тестирование, но продолжаю получать следующую ошибку при запуске теста:
Chrome 77.0.3865 (Windows 10.0.0) FooterComponent should create FAILED
TypeError: Cannot read property 'on' of undefined
......
Мой файл спецификаций выглядит так:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FooterComponent } from './footer.component';
import { TranslateModule } from '@ngx-translate/core';
import { ElectronService } from '../services';
describe('FooterComponent', () => {
let component: FooterComponent;
let fixture: ComponentFixture<FooterComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
FooterComponent
],
providers: [ElectronService ],
imports: [
TranslateModule.forRoot()
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FooterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
// ERROR IS HERE
expect(component).toBeTruthy();
});
});
Внутри углового компонента я подписываюсьдля события Electron:
constructor(private electronService: ElectronService) {
this.electronService.ipcRenderer.on('appVersion', (event, arg) => {
this.appVersion = arg;
});
}
Это то, что приводит к сбою теста, ipcRenderer не определен. Кто-нибудь знает, как я могу провести модульное тестирование углового компонента, в котором используется IPC Электроны?
Электронный сервис, который используется в компоненте, был добавлен к поставщикам в файле спецификации.