0

After running ng test, my Angular 5 app keeps returning errors like

Can't bind to 'routerLink' since it isn't a known property of 'button'.

and

Can't bind to 'ngModel' since it isn't a known property of 'select'.

It was generated by Angular-CLI.

Going in to my app.component.spec.ts file...

import { RouterTestingModule } from '@angular/router/testing'
import { AppComponent } from './app.component'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { UserService } from './user-account/user.service'

describe('AppComponent', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [
        RouterTestingModule,
        FormsModule,
        ReactiveFormsModule
      ],
      declarations: [
        AppComponent
      ],
      providers: [
        UserService
      ]
    })
    TestBed.compileComponents()
  })

  it('should create the app', async(() => {
    const fixture = TestBed.createComponent(AppComponent)
    const app = fixture.debugElement.componentInstance
    expect(app).toBeTruthy()
  }))

  it(`should have as title 'app works!'`, async(() => {
    const fixture = TestBed.createComponent(AppComponent)
    const app = fixture.debugElement.componentInstance
    expect(app.title).toEqual('app works!')
  }))

  it('should render title in a h1 tag', async(() => {
    const fixture = TestBed.createComponent(AppComponent)
    fixture.detectChanges()
    const compiled = fixture.debugElement.nativeElement
    expect(compiled.querySelector('h1').textContent).toContain('app works!')
  }))
})

Since I'm importing the FormsModule and RouterTestingModule, I shouldn't be seeing these errors, right? I've closed and re-ran the test after saving but that has not fixed it either.

  • Possible duplicate of [angular2 testing: Can't bind to 'ngModel' since it isn't a known property of 'input'](https://stackoverflow.com/questions/39584534/angular2-testing-cant-bind-to-ngmodel-since-it-isnt-a-known-property-of-in) – nircraft Apr 23 '19 at 16:35
  • It's not. I've done exactly as the answer stated and am still seeing my errors. – Evan Starr Apr 23 '19 at 17:59

0 Answers0