Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

362
Views
Caso de prueba de unidad angular: no se pueden leer las propiedades de undefined (leyendo 'forEachNode')

Estoy tratando de escribir casos de prueba de unidad para Grid, para esto necesito recorrer los datos de gridapi pero me está dando el error Cannot read undefined forEachNode.

miComponente.componente.ts.

 import { Component, OnInit, } from '@angular/core'; import { GridOptions, GridApi, } from "ag-grid-community"; @Component({ selector: 'my-component', templateUrl: './mycomponent.component.html', styleUrls: ['./mycomponent.component.scss'] }) export class MyComponent implements OnInit { grid: GridOptions; data; constructor() {} getData() { this.grid.api.forEachNode((node) => this.data.push(node.data.id); ); } }

micomponente.componente.spec.ts:

 import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { Mycomponent} from './mycomponent.component'; describe('Mycomponent', () => { let component: Mycomponent; let fixture: ComponentFixture<Mycomponent>; beforeEach( waitForAsync(() => { TestBed.configureTestingModule({ declarations: [Mycomponent], }).compileComponents(); }) ); beforeEach(() => { fixture = TestBed.createComponent(Mycomponent); component = fixture.componentInstance; const gridObj = jasmine.createSpyObj('grid', [ 'api', ]); gridObj.grid.api.and.returnValue({ context: {} data : { id:1,name: 'columName'} }); component.grid = gridObj; fixture.detectChanges(); }); it(`should call getData method.`, () => { component.getData(); expect(component.data).toEqual('[1]'); }); });

Cuando trato de ejecutar el caso de prueba anterior, TypeError: No se pueden leer las propiedades de undefined (leyendo 'forEachNode'). ¿Alguien puede decirme dónde estoy haciendo mal?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!