How to mock AG-Grid Grid options like onSortChanged, onColumnResized, and getDetailedRowData...

Discussão em 'Angular' iniciado por Perumal Samy S, Março 19, 2025.

  1. I'm working on an Angular application that uses AG-Grid, and I need to write unit tests for components that interact with the grid. Specifically, I want to mock the following grid options:

    1. onSortChanged
    2. onColumnResized
    3. getDetailedRowData

    I want to ensure that these methods are called correctly and test their behavior in isolation. However, I'm not sure how to create mocks for these options and integrate them into my tests.

    Here are some additional details about my setup:

    I'm using Jasmine for unit testing.

    The grid options are passed to the AG-Grid component via the gridOptions property.

    const detailCellRendererParams: Partial<IDetailCellRendererParams> = {
    detailGridOptions: {
    headerHeight: 0,
    columnDefs: [
    {
    field: TableColumn.DOCUMENT_NAME,
    minWidth: 400,
    cellRenderer: TableCellRendererComponent,
    },
    {
    field: TableColumn.LOCATION,
    minWidth: 100,
    cellRenderer: TableCellRendererComponent,
    },
    ],
    defaultColDef: {
    flex: 1,
    },
    theme: themeQuartz.withParams({
    wrapperBorderRadius: 0,
    wrapperBorder: '1px solid red',
    }),
    domLayout: 'autoHeight',
    },
    getDetailRowData: (params: GetDetailRowDataParams) => {
    //
    },
    };
    this.gridOptions = {
    masterDetail: true,
    detailCellRendererParams,
    onColumnResized: (event) => {
    //
    },
    onSortChanged: (event) => {
    //
    },
    };

    Continue reading...

Compartilhe esta Página