在测试时,声明的变量未在规范中定义

时间:2017-06-18 05:02:13

标签: angular karma-jasmine

这是我的实际AzureService

cornerRadius

这是我的信息中心规范

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

仪表板组件承包商我正在注入天蓝色服务:

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();
  }));

测试失败表明我没有定义WindowAzure,但我想在哪里定义?

这是错误:

enter image description here

1 个答案:

答案 0 :(得分:0)

在模块级别声明变量

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

这样它就可以在组件,服务之间共享。

还可以将它们导入到用作

的位置
import { WindowsAzure } from '../azure.service.ts'