У меня здесь есть стек-блиц - https://stackblitz.com/edit/ng-graph-tooltip?file=src%2Fapp%2Fbar-chart.ts
Это простая диаграмма D3 на Angular.
Я пытаюсь написать модульный тест, чтобы проверить, создан ли svg.
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FirstVLastGraphComponent } from './first-v-last-graph.component';
import {NO_ERRORS_SCHEMA} from "@angular/core";
describe('FirstVLastGraphComponent', () => {
let component: FirstVLastGraphComponent;
let fixture: ComponentFixture<FirstVLastGraphComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ FirstVLastGraphComponent ],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FirstVLastGraphComponent);
component = fixture.componentInstance;
component.data = [];
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should render an svg', ()=>{
const svgCon = component.initSvg();
expect(svgCon).toContain( );
});
});
Могу ли я проверить, был ли создан элемент HTML в 'toContain ()'