测试时规范中未定义声明的变量 [英] Varaible declared is not defined in spec while testing
本文介绍了测试时规范中未定义声明的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我实际的AzureService
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);}
}
这是我的仪表板规格
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) { }
测试失败,表明我尚未定义WindowAzure,但是我应该在哪里定义?
The test is failing stating that i have not defined WindowAzure, but where am i suppose to define?
这是错误:
推荐答案
在模块级别声明变量
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'
这篇关于测试时规范中未定义声明的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文