【问题标题】:Angular Jasmine Karma issue [SortKey] and many elements on pageAngular Jasmine Karma 问题 [SortKey] 和页面上的许多元素
【发布时间】: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


    【解决方案1】:

    [sortKey]="'userid'" 更改为sortKey="'userid'",或者如果您想在(本机网络元素)上使用绑定,请使用attr,例如 [attr.sortKey]="someVariable"

    【讨论】:

      猜你喜欢
      • 2015-10-19
      • 2016-07-18
      • 2015-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多