Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having issues when importing modules into tests #132

Closed
Azuka opened this issue Mar 19, 2022 · 3 comments
Closed

Having issues when importing modules into tests #132

Azuka opened this issue Mar 19, 2022 · 3 comments

Comments

@Azuka
Copy link

Azuka commented Mar 19, 2022

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 angular/components#23907?

@xidedix
Copy link
Member

xidedix commented Mar 21, 2022

@Azuka

  • what's your version of Angular?

@Azuka
Copy link
Author

Azuka commented Mar 21, 2022

@Azuka

  • what's your version of Angular?

@xidedix Angular 13 with Jest

@xidedix
Copy link
Member

xidedix commented Mar 21, 2022

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.

@xidedix xidedix closed this as completed Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants