Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
  });
});
like image 200
bobbyrne01 Avatar asked May 30 '17 14:05

bobbyrne01


1 Answers

Did you perhaps mean this:

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

The expression you have there just accesses a bunch of properties, you need some kind of function call for it to actually do anything.

like image 162
Duncan Avatar answered Oct 16 '22 05:10

Duncan