运行tslint时,在角度单元测试中“未使用的表达式,预期赋值或函数调用”

时间:2017-05-30 14:35:30

标签: angular typescript lint

有没有办法修复此错误而无需在文件中放置忽略?

运行命令时出错:

./node_modules/tslint/bin/tslint -p src/tsconfig.json --type-check src/app/app.component.spec.ts
[21, 5]: unused expression, expected an assignment or function call

测试:

let chai = require('chai');
let expect = chai.expect;

import { AppComponent } from './app.component';

import { ComponentFixture, TestBed } from '@angular/core/testing';

describe('AppComponent', function() {
  let testAppComponent: AppComponent;
  let fixture: ComponentFixture<AppComponent>;

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [AppComponent]
    });
    fixture = TestBed.createComponent(AppComponent);
    testAppComponent = fixture.componentInstance;
  });

  it('should create the correct component', () => {
    expect(testAppComponent instanceof AppComponent).to.be.true;
  });
});

1 个答案:

答案 0 :(得分:2)

您是否意味着这个:

expect(testAppComponent instanceof AppComponent).toBe(true);

你所拥有的表达式只是访问了一堆属性,你需要某种函数调用来实际执行任何操作。