Skip to content

Instantly share code, notes, and snippets.

@homj
Created March 16, 2023 08:46
Show Gist options
  • Save homj/24e2d3898d013013616304d1faff4315 to your computer and use it in GitHub Desktop.
Save homj/24e2d3898d013013616304d1faff4315 to your computer and use it in GitHub Desktop.
ngx-echarts test teardown bug
import { Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import * as echarts from 'echarts';
import { NgxEchartsDirective, NgxEchartsModule } from 'ngx-echarts';
@Component({
template: '<div echarts [options]="options"></div>'
})
class TestHostComponent {
options?: echarts.EChartsOption;
}
describe('echarts integration', () => {
let component: TestHostComponent;
let fixture: ComponentFixture<TestHostComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
NgxEchartsModule.forRoot({ echarts })
],
declarations: [
TestHostComponent
]
}).compileComponents();
fixture = TestBed.createComponent(TestHostComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should change the options', () => {
const echarts = fixture.debugElement.query(By.directive(NgxEchartsDirective)).injector.get(NgxEchartsDirective);
component.options = {
series: [
{
type: 'gauge',
data: [{ value: 0.3 }]
}
]
};
fixture.detectChanges();
expect(echarts.options).toBe(component.options);
});
});
@xieziyu
Copy link

xieziyu commented Mar 16, 2023

Hi @homj,

I can't reproduce the error when test it with Jest or Karma. Both of the tests are passed.

Error: 1 component threw errors during cleanup

Do I miss anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment