本文整理汇总了TypeScript中angular2/testing_internal.TestComponentBuilder.overrideProviders方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TestComponentBuilder.overrideProviders方法的具体用法?TypeScript TestComponentBuilder.overrideProviders怎么用?TypeScript TestComponentBuilder.overrideProviders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular2/testing_internal.TestComponentBuilder
的用法示例。
在下文中一共展示了TestComponentBuilder.overrideProviders方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: inject
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideProviders(ContactFormComponent, [provide(ContactService, { useValue: contactService })])
.createAsync(ContactFormComponent).then((fixture) => {
fixture.detectChanges();
const originalLength = contacts.length;
expect(originalLength).toBeGreaterThan(0);
const cmp: ContactFormComponent = fixture.componentInstance;
const newContact: Contact = { name: 'Test', email: 'test@example.com' };
cmp.contact = newContact;
cmp.save();
fixture.detectChanges();
const createdContact = contacts[originalLength];
expect(contacts.length).toBe(originalLength + 1);
expect(createdContact.name).toEqual(newContact.name);
expect(createdContact.email).toEqual(newContact.email);
expect(cmp.contact).toEqual({});
async.done();
});
}));
示例2: inject
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideProviders(ContactComponent, [provide(ContactService, { useValue: contactService })])
.createAsync(ContactComponent).then((fixture) => {
fixture.detectChanges();
const cmp: ContactComponent = fixture.componentInstance;
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h2').textContent).toEqual('Contacts!');
const itemsSelector = 'tbody tr';
function obtainContactsLenght() {
return compiled.querySelectorAll(itemsSelector).length;
}
const originalLength = obtainContactsLenght();
let newLength = originalLength;
expect(originalLength).toBeGreaterThan(0);
expect(originalLength).toBe(contacts.length);
const existingContact = ObjectUtil.clone(contacts[0]);
cmp.select(existingContact._id);
fixture.detectChanges();
const selectedContact = cmp.selectedContact;
expect(selectedContact._id).toBe(existingContact._id);
expect(selectedContact.name).toBe(existingContact.name);
cmp.remove(new Event('mock'), existingContact);
fixture.detectChanges();
newLength--;
expect(obtainContactsLenght()).toBe(newLength);
async.done();
});
}));
示例3: createInjector
function createInjector(tcb: TestComponentBuilder, proviers: any[]): Promise<Injector> {
return tcb.overrideProviders(MyComp, [proviers])
.createAsync(MyComp)
.then((fixture) => fixture.componentInstance.injector);
}