"Cannot assign to Service because it is not a variable" 使用 Angular 4 Testbed e2e 测试
"Cannot assign to Service because it is not a variable" using Angular 4 Testbed e2e testing
我正在将 Angular 4 与 TestBed 一起使用,根据此处的文档:https://angular.io/guide/testing#service-tests
我有一个简单的服务:
@Injectable()
export class SimpleService {
getValue() { return 'Hi'; }
}
还有一个测试,使用 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');
});
});
但是,运行 这个带有 ng e2e
的测试给出了以下错误:
Cannot assign to 'SimpleService' because it is not a variable
我需要改变什么?
这看起来像是单元测试,而不是端到端测试。如果你 运行 它与 ng test
它应该工作得很好。
我正在将 Angular 4 与 TestBed 一起使用,根据此处的文档:https://angular.io/guide/testing#service-tests
我有一个简单的服务:
@Injectable()
export class SimpleService {
getValue() { return 'Hi'; }
}
还有一个测试,使用 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');
});
});
但是,运行 这个带有 ng e2e
的测试给出了以下错误:
Cannot assign to 'SimpleService' because it is not a variable
我需要改变什么?
这看起来像是单元测试,而不是端到端测试。如果你 运行 它与 ng test
它应该工作得很好。