本文整理汇总了TypeScript中@angular/core/testing.injectAsync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript injectAsync函数的具体用法?TypeScript injectAsync怎么用?TypeScript injectAsync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了injectAsync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('UserService Service', () => {
beforeEachProviders(() => [API_PROVIDERS]);
it('should contain persisted model methods',
inject([RoomApi], (service: RoomApi) => {
expect(service).toBeTruthy();
expect(service.create).toBeTruthy();
expect(service.updateAll).toBeTruthy();
expect(service.updateAttributes).toBeTruthy();
expect(service.find).toBeTruthy();
expect(service.findById).toBeTruthy();
expect(service.findOne).toBeTruthy();
})
);
let room: RoomInterface = new Room();
room.name = Date.now().toString();
it('should create a new room instance',
injectAsync([RoomApi], (roomApi: RoomApi) => {
return roomApi.create(room)
.subscribe((room: RoomInterface) => expect(room.id).toBeTruthy());
})
);
it('should find room instance',
injectAsync([RoomApi], (roomApi: RoomApi) => {
return roomApi.findOne({ where: room })
.subscribe((room: RoomInterface) => expect(room.id).toBeTruthy());
})
);
});
示例2: describe
describe(selector, () => {
it('should instantiate component without fail', injectAsync([], () => {
return setup()
.then(() => promiseWait());
}));
it('should destroy component without fail', injectAsync([], () => {
return setup()
.then((api: ComponentFixture<any>) => api.destroy())
.then(() => promiseWait());
}));
});
示例3: describe
describe('hide', () => {
it('should hide sidenav by name', injectAsync([], () => {
return setup()
.then(() => service.hide('test'));
}));
it('should reject with invalid sidenav name', injectAsync([], () => {
return setup()
.then(() => service.hide('fake'))
.catch(() => Promise.resolve());
}));
});
示例4: describe
describe('md-sidenav-container', () => {
let template = `
<md-sidenav-container>
<md-sidenav name="menu"></md-sidenav>
<md-sidenav name="right" align="right"></md-sidenav>
</md-sidenav-container>`;
it('should be created and destroyed', injectAsync([], () => {
return setup(template).then((api: ITestFixture) => {
api.fixture.destroy();
});
}));
it('should maintain a query list of its children', injectAsync([], () => {
return setup(template).then((api: ITestFixture) => {
expect(api.container.children.length).toBe(2);
api.fixture.destroy();
});
}));
it('should hide any open children when the backdrop is hidden', injectAsync([], () => {
return setup(template).then((api: ITestFixture) => {
let menu: MdSidenav = service.find('menu');
return menu.show().then(() => {
return new Promise((resolve) => {
expect(menu.visible).toBe(true);
let sub = menu.onHidden.subscribe(() => {
expect(menu.visible).toBe(false);
sub.unsubscribe();
resolve();
});
menu.backdropRef.onClick();
});
})
.then(() => promiseWait())
.then(() => api.fixture.destroy());
});
}));
it('should set isPushed if any child elements are side style', injectAsync([], () => {
return setup(template).then((api: ITestFixture) => {
expect(api.container.isPushed).toBe(false);
let menu: MdSidenav = service.find('menu');
menu.style = SidenavStyle.SIDE;
return menu.show()
.then(() => {
expect(api.container.isPushed).toBe(true);
})
.then(() => promiseWait())
.then(() => api.fixture.destroy());
});
}));
});
示例5: describe
describe('TitleFormComponent', () => {
it('should emit submit event with specified title value',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(TitleFormComponent)
.then((fixture) => {
// const uut: TitleFormComponent = fixture.componentInstance;
// const el: HTMLElement = fixture.nativeElement;
// spyOn(uut.onSubmit, 'emit');
// const input = <HTMLInputElement> el.querySelector('input');
// const btn = <HTMLButtonElement> el.querySelector('button');
// input.value = 'foo';
// uut['title'] = 'foo';
// btn.click();
// fixture.detectChanges();
// expect(uut.onSubmit.emit).toHaveBeenCalled();
});
}));
});
示例6: describe
describe('LoginService', () => {
let testResponse =
{
success: true,
message: "logged in"
};
beforeEachProviders(() => {
return [
HTTP_PROVIDERS,
provide(XHRBackend, { useClass: MockBackend }),
LoginService
];
});
it('should login', inject([XHRBackend, LoginService], (mockBackend, service) => {
mockBackend.connections.subscribe(
(connection: MockConnection) => {
connection.mockRespond(new Response(
new ResponseOptions({
body: testResponse
}
)));
});
let req = {};
req.username = "test";
req.password = "test";
service.login(req).subscribe((res: ServiceResponse) => {
expect(res.success).toBe(true);
expect(res.message).toBe("logged in");
});
}));
it('should should login async', injectAsync([XHRBackend, LoginService], (mockBackend, service) => {
return new Promise((pass, fail) => {
mockBackend.connections.subscribe(
(connection: MockConnection) => {
connection.mockRespond(new Response(
new ResponseOptions({
body: testResponse
}
)));
});
service.login().subscribe((res: ServiceResponse) => {
expect(res.success).toBe(true);
expect(res.message).toBe("logged in");
pass();
});
});
}));
});
示例7: describe
describe('MyApp', () => {
beforeEachProviders(() => [
provide(NavParams, {useClass: MockNavParams}),
provide(ViewController, {useClass: MockClass}),
provide(Platform, {useClass: MockClass}),
Book
]);
beforeEach(injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(EditBookModal)
.then((componentFixture: ComponentFixture<Type>) => {
editBookModalFixture = componentFixture;
editBookModal = componentFixture.componentInstance;
editBookModalFixture.detectChanges();
})
.catch((err) => {
console.error('ERROR - An error has occurred inside a promise! ' + err);
// throw the error out to the console - http://stackoverflow.com/a/30741722
setTimeout(function(): void { throw err; });
});
}));
it('initialises', () => {
expect(editBookModal).not.toBeNull();
expect(editBookModalFixture).not.toBeNull();
});
});
示例8: describe
describe('Page2', () => {
beforeEachProviders(() => [
Form,
provide(NavController, {useClass: MockClass}),
provide(NavParams, {useClass: MockClass}),
provide(Config, {useClass: MockClass}),
provide(IonicApp, {useClass: MockClass}),
provide(Platform, {useClass: MockClass}),
]);
beforeEach(injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(Page2)
.then((componentFixture: ComponentFixture<Page2>) => {
page2Fixture = componentFixture;
page2 = componentFixture.componentInstance;
page2Fixture.detectChanges();
})
.catch(Utils.promiseCatchHandler);
}));
it('initialises', () => {
expect(page2).not.toBeNull();
expect(page2Fixture).not.toBeNull();
});
});
示例9: describe
describe('Directive: MaterializeCollection', () => {
let fixture:ComponentFixture<any>;
beforeEachProviders(() => [TestComponentBuilder]);
beforeEach(injectAsync([TestComponentBuilder], tcb => {
return tcb
.createAsync(Container)
.then((f:ComponentFixture<any>) => {
f.detectChanges();
fixture = f;
});
}));
it('Initialization should be ok', () => {
expect(fixture).toBeDefined();
});
it('Click event should add active class', () => {
let directive:MaterializeCollection = fixture.componentInstance.children.first;
expect(directive).toBeDefined();
$(directive.el.nativeElement).click();
expect($(directive.el.nativeElement).find('li.active').length).toBe(0);
});
});
示例10: describe
describe('Component: Modal Content', () => {
let builder: TestComponentBuilder;
beforeEachProviders(() => [RioModalContent]);
beforeEach(inject([TestComponentBuilder],
function (tcb: TestComponentBuilder) {
builder = tcb;
}));
it('should inject the component', inject([RioModalContent],
(component: RioModalContent) => {
expect(component).toBeTruthy();
}));
it('should create the component', injectAsync([], () => {
return builder.createAsync(RioModalContentTestController)
.then((fixture: ComponentFixture<any>) => {
fixture.autoDetectChanges();
let query = fixture.debugElement
.query(By.directive(RioModalContent));
expect(query).toBeTruthy();
expect(query.componentInstance).toBeTruthy();
});
}));
});