Varaible declared is not defined in spec while testing

和自甴很熟 提交于 2019-12-12 05:52:02

问题


Here is my actual AzureService

declare var WindowsAzure;
declare var config;

@Injectable()
export class AzureService {
    azureUrl;
    client: any;
    programmes: Programme[];
    selectedProgramme: Programme;
    orderSummary: Order;

    constructor() {
        this.client = new WindowsAzure.MobileServiceClient(this.azureUrl);}
}

Here is my dashboard spec

describe('DashboardComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [
        DashbaordComponent,
        StatusComponent
      ],
      providers:[ AzureService]
    }).compileComponents();
  }));

  it('should create the app', async(() => {
    const fixture = TestBed.createComponent(DashbaordComponent);
    const app = fixture.debugElement.componentInstance;
    expect(app).toBeTruthy();
  }));

Dashboard component contractor where i am injecting azure service:

constructor(private azureService: AzureService) { }

The test is failing stating that i have not defined WindowAzure, but where am i suppose to define?

here is the error:


回答1:


Declare the variables at the module level

declare var WindowsAzure;
declare var config;
@NgModule({...})

So that it is shared across the components,services.

Also import them where ever you are using as

import { WindowsAzure } from '../azure.service.ts'


来源:https://stackoverflow.com/questions/44611879/varaible-declared-is-not-defined-in-spec-while-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!