coreui / coreui-angular

CoreUI Components Library for Angular https://coreui.io/angular/docs/
https://coreui.io/angular/
MIT License
248 stars 146 forks source link

Having issues when importing modules into tests #132

Closed Azuka closed 2 years ago

Azuka commented 2 years ago

OS: MacOs 12.3 Browser: N/A (Unit tests)

Specifically any reference to the DropdownComponent e.g. when using the c-sidebar or c-dropdown component:

import { ComponentFixture, TestBed } from '@angular/core/testing';

import { FullLayoutComponent } from './full-layout.component';
import {SidebarModule} from "@coreui/angular";

describe('Main LayoutComponent', () => {
  let component: FullLayoutComponent;
  let fixture: ComponentFixture<FullLayoutComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [FullLayoutComponent, ],
      imports: [SidebarModule],
    }).compileComponents();
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(FullLayoutComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

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

I get this error:

Test suite failed to run

    ReferenceError: Cannot access 'DropdownComponent' before initialization

      3 | import { FullLayoutComponent } from './full-layout.component';
    > 4 | import {SidebarModule} from "@coreui/angular";
        | ^
      5 |
      6 | describe('Main LayoutComponent', () => {
      7 |   let component: FullLayoutComponent;

      at Object.<anonymous> (../../node_modules/@coreui/angular/fesm2020/coreui-angular.mjs:2599:212)
      at Object.<anonymous> (src/app/layout/full-layout.component.spec.ts:5:1)
      at TestScheduler.scheduleTests (../../node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (../../node_modules/@jest/core/build/runJest.js:404:19)
      at _run10000 (../../node_modules/@jest/core/build/cli/index.js:320:7)
      at runCLI (../../node_modules/@jest/core/build/cli/index.js:173:3)

Is this related to the order the components are defined, or partial JIT compilation like in https://github.com/angular/components/issues/23907?

xidedix commented 2 years ago

@Azuka

Azuka commented 2 years ago

@Azuka

  • what's your version of Angular?

@xidedix Angular 13 with Jest

xidedix commented 2 years ago

It seems the mentioned partial compilation output issue has been fixed with Angular 13.0.1

We are closing this as the problem is not necessarily related to CoreUI. Maybe it comes from your jest config? See:

Feel free to comment or reopen if you think this is a CoreUI issue.