dimanche 27 septembre 2020

Cannot read property 'textContent' of null Angular Testing

I have simple angular application with AppComponent and ProductComponent. When I run ng test command, getting below error on http://localhost:9876/?id=80860281

Jesmine 3.5.0Options
finished in 0.473s
4 specs, 1 failure, randomized with seed 16102
Spec List | Failures
AppComponent > should render title
TypeError: Cannot read property 'textContent' of null
at <Jasmine>
at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/src/app/app.component.spec.ts:33:51)
at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:364:1)
at ProxyZoneSpec.push../node_modules/zone.js/dist/zone-testing.js.ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:292:1)
at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:363:1)
at Zone.run (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:123:1)
at runInTestZone (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:545:1)
at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:560:1)
at <Jasmine>

This is my code

app.module.ts class

@NgModule({
declarations: [
AppComponent,
ProductComponent
],
imports: [
BrowserModule,
FormsModule,
AppRoutingModule 
],
providers: [],
bootstrap: [AppComponent]})

app.component.ts class

import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'Product';
}

files app.component.spec.ts and product.component.spec.ts have the default code. I didn't modified those files.

How can I fix this issue?

Aucun commentaire:

Enregistrer un commentaire