Skip to content

Error with Angular unit testing with @ngneat/spectatorΒ #544

@sarathkrishna99

Description

@sarathkrishna99

Hi,

I wrote the below unit test using @ngneat/spectator

const createComponent = createComponentFactory({
        component: TableComponent,
        shallow: true,
        declarations: [MockComponent(SingleSelectComponent)],
        imports: [
            FormsModule,
            ReactiveFormsModule,
            ButtonModule,
            DropdownModule,
            RadioButtonModule,
            HttpClientTestingModule,
            TooltipModule,
            TableModule,
            AutoCompleteModule,
            InputSwitchModule,
        ],
        schemas: [CUSTOM_ELEMENTS_SCHEMA],
        providers: [{
            provide: Service,
            useValue: {
                fetchRecords: () => of({}),
                add: () => of({}),
                getDetails: () => of({}),

            }
        }
        ]
    });
    beforeEach(() => {
        spectator = createComponent();
        service = spectator.inject(Service);

    });

    it('should create', () => {
        expect(spectator.component).toBeTruthy();
    });

    it('should set intial values for rowsPerPageOptions', () => {
        expect(spectator.component.tableRowsPerPageOptions.length).toEqual(3);
        const rowsPerPageOptions = [10, 20, 50];
        spectator.component.tableRowsPerPageOptions.forEach((option, i) => {
            expect(option).toEqual(rowsPerPageOptions[i]);
        })
    });

But when I ran the above test, I am getting the below error. Can you please tell me what I am doing wrong

TableComponent > should set intial values for rowsPerPageOptions
Failed: Cannot read properties of undefined (reading 'length')
error properties: Object({ longStack: 'TypeError: Cannot read properties of undefined (reading 'length')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions