當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript TestComponentBuilder.overrideProviders方法代碼示例

本文整理匯總了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();
          });
      }));
開發者ID:truckfondue,項目名稱:angular2-minimalist-starter,代碼行數:30,代碼來源:contact-form.component_spec.ts

示例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();
          });
      }));
開發者ID:brunkb,項目名稱:a2-contact,代碼行數:45,代碼來源:spec.ts

示例3: createInjector

 function createInjector(tcb: TestComponentBuilder, proviers: any[]): Promise<Injector> {
   return tcb.overrideProviders(MyComp, [proviers])
       .createAsync(MyComp)
       .then((fixture) => fixture.componentInstance.injector);
 }
開發者ID:CutiePanther,項目名稱:angular,代碼行數:5,代碼來源:regression_integration_spec.ts


注:本文中的angular2/testing_internal.TestComponentBuilder.overrideProviders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。