问题
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