When I run Karma with Jasmine tests, I encounter the following error message:
The issue is that 'ngModel' cannot be bound since it is not recognized as a property of 'textarea'.
Even though I have imported FormsModule into my app.module and added it to testBed, this error only occurs when running Karma.
The application functions correctly, and there are no sub-modules present.
I am using Angular 4.0.0 along with Angular CLI 1.0.4.
app.module.ts
@NgModule({
declarations: [
AppComponent,
NoteComponent,
NotesListComponent,
AddNoteButtonComponent,
AboutComponent,
NoteWrapperComponent,
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
CommonModule,
RouterModule.forRoot([ /** Rest of the code... **/
note.component.html
<textarea title="" class="no-extra n-note__textarea n-note__textarea--transparent" [(ngModel)]="note.description"
name="description" (blur)="updateNote($event)">
{{note.description}}
</textarea>
note.component.spec.js
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpModule } from '@angular/http';
import { expect, assert } from 'chai';
import { NoteComponent } from './note.component';
import { Note } from './note';
import { BrowserModule } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
describe('NoteComponent', () => {
let component: NoteComponent;
let fixture: ComponentFixture<NoteComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [NoteComponent],
imports: [HttpModule, BrowserModule, CommonModule, FormsModule],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NoteComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should be defined', () => {
assert.isDefined(NoteComponent);
});
it('should be created', () => {
expect(component).to.be.an('object');
});
describe('public API', () => {
const note: Note = new Note(1, '', '');
it('markAsDone method should set done parameter to true', () => {
component.note = note;
component.markAsDone();
expect(note._done).to.be.true;
});
it('markAsDiscarded method should set discarded parameter to true', () => {
component.note = note;
component.markAsDiscarded();
expect(note._deleted).to.be.true;
});
it('markAsStarred method should set starred parameter to true', () => {
component.note = note;
component.markAsStarred();
expect(note._starred).to.be.true;
});
});
});