Error .spec.ts in Angular5

1

I have the following error caused in the spec.ts

It is given by this function.

 beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [UserPanelComponent]
    }).compileComponents();
  }));

The description is:

[Jest]{{ [ERROR ->]'userPanelUserRol' | translate:userPanelUserRol }}</span> </strong> </li>"):
     ng:///DynamicTestModule/UserPanelComponent.html@6:15
    The pipe 'translate' could not be found (" </li> <li> <a href="#" clrDropdownItem>{{ [ERROR ->]'userPanelUserInformation' | translate:userPanelUserInformation }}</a> </li> <li>"): ng:///DynamicTestModule/UserPanelComponent.html@10:35
    The pipe 'translate' could not be found (" </li> <li> <a href="#" clrDropdownItem>{{ [ERROR ->]'userPanelPassword' | translate:userPanelPassword }}
</a> </li> <li>"):
 ng:///DynamicTestModule/UserPanelComponent.html@13:35The pipe 'translate' could not be found (" </li> <li> <button class="btn-disconnect"> {{ 
[ERROR ->]'userPanelLogout' | translate:userPanelLogout }}</button> </li></ul>"): ng:///DynamicTestModule/UserPanelComponent.html@16:39

I do not understand why it gives an error in this file if I have not touched it, and I do not know that because it gives an error if everything works correctly.

New ----

> >
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule, TranslateLoader, TranslateFakeLoader } from '@ngx-translate/core';
import { UserPanelComponent } from './user-panel.component';
import { ConfigService } from '../config.service';
import { NO_ERRORS_SCHEMA } from '@angular/core';

describe('UserPanelComponent', () => {
  let component: UserPanelComponent;
  let fixture: ComponentFixture<UserPanelComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [UserPanelComponent],
      providers: [ConfigService],
      schemas: [NO_ERRORS_SCHEMA],
      imports: [
        TranslateModule.forRoot({
          loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
        })
      ]
    }).compileComponents();
  }));

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

The error is:

Invalid provider for the NgModule 'DynamicTestModule' - only instances of Provider and Type are allowed, got: [?[object Object]?, ...]

The new error is split undefined

    
asked by EduBw 18.04.2018 в 11:01
source

1 answer

1

When you created your application, you had to define the components in a module, you probably have them in app.module.ts .

In the same way, when you added ngx-translate, which is a module itself, you had to declare it as imported.

The same thing you have to do in the test module, add it.

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [UserPanelComponent],
      providers: [{ ConfigService }],
      schemas: [NO_ERRORS_SCHEMA],
      imports: [
        TranslateModule.forRoot({
          loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
        })
      ]
    }).compileComponents();
  }));

You can find examples here

    
answered by 18.04.2018 / 11:38
source