【发布时间】:2018-04-09 18:29:24
【问题描述】:
当我正在构建一些页面并添加 karma 使用 Angular 5 运行的 jasmine .spec 文件时,我遇到了很多错误
chrome 和命令提示符下的示例
错误:模板解析错误: 无法绑定到“sortKey”,因为它不是“th”的已知属性。 ("
我什至没有测试这个sortkey 所以我很困惑为什么它会关心!
这是 HTML 模板代码
<th class="col-sm-3" sortColumn [sortKey]="'userid'"(click)="assignsort('userid')" [data]="assign">User Id
这就是我的规范文件的样子
import { AssignSearchComponent } from './assign-search.component';
import { BrowserModule, By } from "@angular/platform-browser";
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
describe('AssignSearchComponent', () => {
let component: AssignSearchComponent;
let fixture: ComponentFixture<AssignSearchComponent>;
//let debugEl: DebugElement;
let inputEl: HTMLInputElement;
let element: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AssignSearchComponent],
imports: [BrowserModule, FormsModule, ReactiveFormsModule, CommonModule]
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(AssignSearchComponent);
component = fixture.componentInstance;
});
it('should create Assign Search component', () => {
expect(component).toBeTruthy();
})
});
如您所见,我在 html 上使用了 [sortKey],但我没有测试 SPEC 文件。我需要做些什么才能使其合规?
【问题讨论】:
标签: angular jasmine karma-runner karma-jasmine