Here is the source code:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';
import { HomePage } from './home.page';
import { LevelGridComponent } from '../level/level-grid/level-grid.component';
import { SidebarComponent } from '../sidebar/sidebar.component';
import { LevelStatusSidebarComponent } from '../level/level-status-sidebar/level-status-sidebar.component';
describe('HomePage', () => {
let component: HomePage;
let fixture: ComponentFixture<HomePage>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
HomePage,
LevelGridComponent,
SidebarComponent,
LevelStatusSidebarComponent
],
imports: [IonicModule.forRoot()]
}).compileComponents();
fixture = TestBed.createComponent(HomePage);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it('should create', () => {
expect(component).toBeTruthy();
});
});
Now the test opens the browser, renders the component and then does nothing, for 5 seconds, and (thus) seems to time out:
HomePage should create FAILED Error: Timeout - Async callback was not invoked within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) in node_modules/jasmine-core/lib/jasmine-core/jasmine.js (line 5494)
Things that happened before
Previously, I had the usual Angular "this module is not defined" error, i.e.:
'app-level-status-sidebar' is not a known element:
1. If 'app-level-status-sidebar' is an Angular component, then verify that it is part of this module.
2. If 'app-level-status-sidebar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
To fix this, I've added the real components to "declarations" as you can see above.
As the test is actually very simple, I do not expect any issues here, and it also seems to run (I've added console.log statements and they were executed in it('should create'
.) As the test function does not actually initiate any async function and is 100% synchronous, I did not expect anything to fail here.
For testing I've also added an explicit done
function call to the it
test function and call it at the end, but that does not change anything.
Aucun commentaire:
Enregistrer un commentaire