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

Can't test using Angular testing modules #380

Open
xndyz opened this issue Dec 15, 2022 · 3 comments
Open

Can't test using Angular testing modules #380

xndyz opened this issue Dec 15, 2022 · 3 comments

Comments

@xndyz
Copy link

xndyz commented Dec 15, 2022

Currently unable to test a custom component which renders the ngx-echarts component. It's not recognizing the directives despite importing the directive to the TestBed, nor does it skip when using NO_ERRORS_SCHEMA.

It gives Can't bind to ___ since it isn't a known property of 'div' errors for each eCharts attribute used in the template file.

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [GridMixChartComponent],
      imports: [
        HttpClientTestingModule,
        CommonModule,
        TranslateModule.forRoot(),
        NgxEchartsModule.forRoot({
          /**
           * This will import all modules from echarts.
           * If you only need custom modules,
           * please refer to [Custom Build] section.
           */
          echarts: () => import('echarts'), // or import('./path-to-my-custom-echarts')
        }),
      ],
      providers: [
        { provide: GridMixService, useClass: mockGridMixService },
        { provide: AppStore, useClass: mockAppStore },
      ],
      schemas: [NO_ERRORS_SCHEMA],
    }).compileComponents();
  });

image

@xndyz xndyz changed the title Can't bind to ___ since it isn't a known property of 'div' Can't test using Angular testing modules Dec 15, 2022
@Neizan93
Copy link

Neizan93 commented Dec 21, 2022

Similar issue, but my problem is:

ng serve: OK
ng build: OK

ng test: FAILS
(using jest)

testfail

"echarts": "^5.4.1"
"ngx-echarts": "^8.0.1"

note: Tested on a karma+jasmine proyect without errors.
Seems to be an error with Jest and it is a different error (opening new thread...)

@edilson14
Copy link

@Neizan93 orr @Fandy
does any one find the problem ?
ng test fails here to :/

@Pechoquintas
Copy link

You can try the following, it worked for me, remove NgxEchartsModule from the imports section, and add the following in the providers.

providers: [
  ...(NgxEchartsModule.forRoot({
    echarts: async () => {
      const echarts = await import('echarts');
      return echarts;
    },
  }).providers || []),
],
schemas: [NO_ERRORS_SCHEMA]

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

4 participants