Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

336
Views
MatFormFieldHarness no se puede identificar a partir de la prueba de unidad angular

Este es el archivo de prueba.

 describe('test', () => { let component: myComponent; let fixture: ComponentFixture<myComponent> let loader: HarnessLoader; beforeEach(() => { fixture = TestBed.createComponent(myComponent); component = fixture.componentInstance; fixture.detectChanges(); loader = TestbedHarnessEnvironment.loader(fixture); }); it('check label', async () => { const form = await loader.getHarness(MatFormFieldHarness); // error line const label = await form.hasLabel(); expect(label).toBeTrue(); }); });

este es el html

 <div class="units-input-container"> <mat-form-field> <mat-label>unit</mat-label> <input type="text" required /> </mat-form-field> </div>

este es el error que me sale

 Error: Uncaught (in promise): Error: Failed to find element matching one of the following queries: (MatFormFieldHarness with host element matching selector: ".mat-form-field") Error: Failed to find element matching one of the following queries:
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debe incluir los módulos de material angular utilizados en su componente, consulte a continuación:

 beforeEach(async () => { await TestBed.configureTestingModule({ imports: [ ReactiveFormsModule, MatFormFieldModule, MatInputModule, NoopAnimationsModule ], declarations: [AppComponent] }) .compileComponents(); });

NOTA: Asumo que está usando un formulario reactivo ( ReactiveFormsModule ) y que puede usar mat-input , por eso MatInputModule . Se requiere NoopAnimationsModule para que la prueba maneje las animaciones.

Para más detalles consulta la documentación (ver documentación ).

Creé un ejemplo simple para experimentar con el marco de arnés. Consulte la prueba 'mat-form-field debe detectar errores después de que se activen las validaciones' en github .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!