Search code examples
angularunit-testingprotractore2e-testingangular-e2e

"Cannot assign to Service because it is not a variable" using Angular 4 Testbed e2e testing


I am using Angular 4 with TestBed, as per the documents here: https://angular.io/guide/testing#service-tests

I have a simple Service:

@Injectable()
export class SimpleService {
  getValue() { return 'Hi'; }
}

And a test, which instantiates this Service using TestBed:

describe('SimpleService', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({ providers: [SimpleService] });
  });

  it('Should say Hello', () => {
    const testBedService: SimpleService = TestBed.get(SimpleService);
    const actual = testBedService.getValue();
    expect(actual).toBe('Hi');
  });
});

However, running this test with ng e2e gives me the following error:

Cannot assign to 'SimpleService' because it is not a variable

What do I need to change?


Solution

  • This looks like a unit test, not an end-to-end test. If you run it with ng test it should work just fine.