'unused expression, expected an assignment or function call' 在 angular 单元测试中 运行 tslint

'unused expression, expected an assignment or function call' in an angular unit test when running tslint

有没有一种方法可以修复这个错误而不必在文件中放置一个忽略?

运行 命令时出错:

./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;
  });
});

你是不是这个意思:

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

你那里的表达式只是访问一堆属性,你需要某种函数调用才能真正做任何事情。