plotly / plotly/angular-plotly.js

Angular Plotly test TypeError: Cannot read properties of undefined (reading 'data')

Open
#257 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
242
Forks
81
Avg merge
8h 48m
Merged PRs (30d)
18

Description

i am having an issue running the tests file for my page

TypeError: Cannot read properties of undefined (reading 'data')
TypeError: Cannot read properties of undefined (reading 'data')
    at PlotlyComponent.createFigure (http://localhost:9876/_karma_webpack_/webpack:/node_modules/angular-plotly.js/__ivy_ngcc__/fesm2015/angular-plotly.js.js:285:21)
    at PlotlyComponent.call [as ngOnDestroy] (http://localhost:9876/_karma_webpack_/webpack:/node_modules/angular-plotly.js/__ivy_ngcc__/fesm2015/angular-plotly.js.js:195:29)
    at executeOnDestroys (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2015/core.mjs:6537:32)
    at cleanUpView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2015/core.mjs:6438:9)
    at destroyViewTree (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2015/core.mjs:6264:21)
    at destroyLView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2015/core.mjs:6416:9)
    at RootViewRef.destroy (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2015/core.mjs:13512:9)
    at ComponentRef.destroy (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2015/core.mjs:13958:23)
    at ComponentFixture.destroy (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2015/testing.mjs:228:31)
    at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/webpack:/src/app/pages/graph.component.spec.ts:163:17)

i am using PlotlyViaWindowModule, when i start ng serve the plot is working correctly without any issues but i cant run the test


describe('GraphComponent', () => {
    let component: GraphComponent;
    let fixture: ComponentFixture<GraphComponent>;
    let debugElement: DebugElement;

    beforeEach(waitForAsync(() => {
        TestBed.configureTestingModule({
            declarations: [... , PlotlyComponent], providers: [...PlotlyService,                 { provide: MyPlotService, useClass: myPlotServiceMock},
],   imports: [
                ...
                PlotlyViaWindowModule,]

beforeEach(() => {
        fixture = TestBed.createComponent(GraphComponent);
        component = fixture.componentInstance;
        debugElement = fixture.debugElement;

    
        fixture.detectChanges();
    });

    it('shoud create the app', () => {
        expect(component).toBeTruthy();
    });

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the failing GraphComponent spec in src/app/pages/graph.component.spec.ts and review the PlotlyViaWindowModule setup. Trace the PlotlyComponent createFigure call during ngOnDestroy, using the reported stack trace as the entry point. Done means the test completes without the TypeError while the component remains usable with ng serve.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, plotly, typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.