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

Viewed 17257

Is there a way to fix this error without having to place an ignore in the file?

Error when running command:

./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

Test:

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;
  });
});
2 Answers

In my case I had a dangling ?

someArray.find(someCheck)?.items.push(someThing)

I just wrote it out as an if statement:

let ok = someArray.find(someCheck);
if (ok) {
 ok.items.push(someThing);
}
Related