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


TypeScript testing_internal.inject函數代碼示例

本文整理匯總了TypeScript中angular2/testing_internal.inject函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript inject函數的具體用法?TypeScript inject怎麽用?TypeScript inject使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了inject函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

    describe('getViewDirectivesMetadata', () => {

      it('should return the directive metadatas',
         inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
           expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
               .toContain(resolver.getDirectiveMetadata(SomeDirective));
         }));

      describe("platform directives", () => {
        beforeEachProviders(
            () => [provide(PLATFORM_DIRECTIVES, {useValue: [ADirective], multi: true})]);

        it('should include platform directives when available',
           inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
             expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
                 .toContain(resolver.getDirectiveMetadata(ADirective));
             expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
                 .toContain(resolver.getDirectiveMetadata(SomeDirective));
           }));
      });
    });
開發者ID:1186792881,項目名稱:angular,代碼行數:21,代碼來源:runtime_metadata_spec.ts

示例2: describe

    describe('hierarchical app', () => {
      beforeEachProviders(
          () => { return [provide(ROUTER_PRIMARY_COMPONENT, {useValue: HierarchyAppCmp})]; });

      it('should bootstrap an app with a hierarchy',
         inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {

           tcb.createAsync(HierarchyAppCmp).then((fixture) => {
             var router = fixture.debugElement.componentInstance.router;
             router.subscribe((_) => {
               expect(fixture.debugElement.nativeElement).toHaveText('root { parent { hello } }');
               expect(fixture.debugElement.componentInstance.location.path())
                   .toEqual('/parent/child');
               async.done();
             });
             router.navigateByUrl('/parent/child');
           });
         }));

      // TODO(btford): mock out level lower than LocationStrategy once that level exists
      xdescribe('custom app base ref', () => {
        beforeEachProviders(() => { return [provide(APP_BASE_HREF, {useValue: '/my/app'})]; });
        it('should bootstrap',
           inject(
               [AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {

                 tcb.createAsync(HierarchyAppCmp).then((fixture) => {
                   var router = fixture.debugElement.componentInstance.router;
                   router.subscribe((_) => {
                     expect(fixture.debugElement.nativeElement)
                         .toHaveText('root { parent { hello } }');
                     expect(fixture.debugElement.componentInstance.location.path())
                         .toEqual('/my/app/parent/child');
                     async.done();
                   });
                   router.navigateByUrl('/parent/child');
                 });
               }));
      });
    });
開發者ID:LordBinary,項目名稱:angular,代碼行數:40,代碼來源:bootstrap_spec.ts

示例3: describe

    describe('when values changes', () => {
      it('should switch amongst when values',
         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
           var template = '<div>' +
               '<ul [ngSwitch]="switchValue">' +
               '<template [ngSwitchWhen]="when1"><li>when 1;</li></template>' +
               '<template [ngSwitchWhen]="when2"><li>when 2;</li></template>' +
               '<template ngSwitchDefault><li>when default;</li></template>' +
               '</ul></div>';

           tcb.overrideTemplate(TestComponent, template)
               .createAsync(TestComponent)
               .then((fixture) => {
                 fixture.debugElement.componentInstance.when1 = 'a';
                 fixture.debugElement.componentInstance.when2 = 'b';
                 fixture.debugElement.componentInstance.switchValue = 'a';
                 fixture.detectChanges();
                 expect(fixture.debugElement.nativeElement).toHaveText('when 1;');

                 fixture.debugElement.componentInstance.switchValue = 'b';
                 fixture.detectChanges();
                 expect(fixture.debugElement.nativeElement).toHaveText('when 2;');

                 fixture.debugElement.componentInstance.switchValue = 'c';
                 fixture.detectChanges();
                 expect(fixture.debugElement.nativeElement).toHaveText('when default;');

                 fixture.debugElement.componentInstance.when1 = 'c';
                 fixture.detectChanges();
                 expect(fixture.debugElement.nativeElement).toHaveText('when 1;');

                 fixture.debugElement.componentInstance.when1 = 'd';
                 fixture.detectChanges();
                 expect(fixture.debugElement.nativeElement).toHaveText('when default;');

                 async.done();
               });
         }));
    });
開發者ID:LordBinary,項目名稱:angular,代碼行數:39,代碼來源:ng_switch_spec.ts

示例4: describe

    describe('compileComponentCodeGen', () => {
      function detectChanges(
          compiler: ChangeDetectionCompiler, template: string,
          directives: CompileDirectiveMetadata[] = CONST_EXPR([])): Promise<string[]> {
        var type =
            new CompileTypeMetadata({name: stringify(SomeComponent), moduleUrl: THIS_MODULE_URL});
        var parsedTemplate = parser.parse(template, directives, 'TestComp');
        var sourceExpressions =
            compiler.compileComponentCodeGen(type, ChangeDetectionStrategy.Default, parsedTemplate);
        var testableModule = createTestableModule(sourceExpressions, 0).getSourceWithImports();
        return evalModule(testableModule.source, testableModule.imports, null);
      }

      it('should watch element properties', inject([AsyncTestCompleter], (async) => {
           detectChanges(compiler, '<div [elProp]="someProp">')
               .then((value) => {
                 expect(value).toEqual(['elementProperty(elProp)=someValue']);
                 async.done();
               });

         }));
    });
開發者ID:mixed,項目名稱:angular,代碼行數:22,代碼來源:change_detector_compiler_spec.ts

示例5: describe

  describe("WebWorkerXHRImpl", () => {
    it("should pass requests through the broker and return the response",
       inject([AsyncTestCompleter], (async) => {
         const URL = "http://www.example.com/test";
         const RESPONSE = "Example response text";

         var messageBroker: any = new SpyMessageBroker();
         messageBroker.spy("runOnService")
             .andCallFake((args: UiArguments, returnType: Type) => {
               expect(args.method).toEqual("get");
               expect(args.args.length).toEqual(1);
               expect(args.args[0].value).toEqual(URL);
               return PromiseWrapper.wrap(() => { return RESPONSE; });
             });

         var xhrImpl = new WebWorkerXHRImpl(new MockMessageBrokerFactory(messageBroker));
         xhrImpl.get(URL).then((response) => {
           expect(response).toEqual(RESPONSE);
           async.done();
         });
       }));
  });
開發者ID:bet4vlom,項目名稱:angular,代碼行數:22,代碼來源:xhr_impl_spec.ts

示例6: describe

    describe("#all", () => {
      it("should combine lists of Promises", inject([AsyncTestCompleter], (async) => {
           var one = PromiseWrapper.completer();
           var two = PromiseWrapper.completer();

           var all = PromiseWrapper.all([one.promise, two.promise]);
           var allCalled = false;

           PromiseWrapper.then(one.promise, (_) => {
             expect(allCalled).toBe(false);
             two.resolve('two');
             return null;
           });

           PromiseWrapper.then(all, (_) => {
             allCalled = true;
             async.done();
             return null;
           });

           one.resolve('one');
         }));

      [null, true, false, 10, 'thing', {}, []].forEach(abruptCompletion => {
        it(`should treat "${abruptCompletion}" as an "abrupt completion"`,
           inject([AsyncTestCompleter], (async) => {
             var one = PromiseWrapper.completer();

             var all = PromiseWrapper.all([one.promise, abruptCompletion]);

             PromiseWrapper.then(all, (val) => {
               expect(val[1]).toEqual(abruptCompletion);
               async.done();
             });

             one.resolve('one');
           }));
      });
    });
開發者ID:1186792881,項目名稱:angular,代碼行數:39,代碼來源:async_spec.ts

示例7: describe

    describe('bootstrap functionality', () => {
      it('should bootstrap a simple app', inject([AsyncTestCompleter], (async) => {
           var fakeDoc = DOM.createHtmlDocument();
           var el = DOM.createElement('app-cmp', fakeDoc);
           DOM.appendChild(fakeDoc.body, el);

           bootstrap(AppCmp,
                     [
                       ROUTER_PROVIDERS,
                       provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
                       provide(LocationStrategy, {useClass: MockLocationStrategy}),
                       provide(DOCUMENT, {useValue: fakeDoc})
                     ])
               .then((applicationRef) => {
                 var router = applicationRef.hostComponent.router;
                 router.subscribe((_) => {
                   expect(el).toHaveText('outer { hello }');
                   expect(applicationRef.hostComponent.location.path()).toEqual('');
                   async.done();
                 });
               });
         }));
    });
開發者ID:,項目名稱:,代碼行數:23,代碼來源:

示例8: describe

    describe('without APP_BASE_HREF', () => {
      beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
        platformLocation = pl;
        locationStrategy = ls;
        platformLocation.spy('pushState');
        platformLocation.pathname = '';
      }));

      it('should prepend urls with a hash for non-empty URLs', () => {
        expect(locationStrategy.prepareExternalUrl('foo')).toEqual('#foo');

        locationStrategy.pushState(null, 'Title', 'foo', '');
        expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '#foo');
      });

      it('should prepend urls with a hash for URLs with query params', () => {
        expect(locationStrategy.prepareExternalUrl('foo?bar')).toEqual('#foo?bar');

        locationStrategy.pushState(null, 'Title', 'foo', 'bar=baz');
        expect(platformLocation.spy('pushState'))
            .toHaveBeenCalledWith(null, 'Title', '#foo?bar=baz');
      });

      it('should prepend urls with a hash for URLs with just query params', () => {
        expect(locationStrategy.prepareExternalUrl('?bar')).toEqual('#?bar');

        locationStrategy.pushState(null, 'Title', '', 'bar=baz');
        expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '#?bar=baz');
      });

      it('should not prepend a hash to external urls for an empty internal URL', () => {
        expect(locationStrategy.prepareExternalUrl('')).toEqual('');

        locationStrategy.pushState(null, 'Title', '', '');
        expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '');
      });
    });
開發者ID:844496869,項目名稱:angular,代碼行數:37,代碼來源:hash_location_strategy_spec.ts

示例9: describe

  describe('preparseElement', () => {
    var htmlParser;
    beforeEach(inject([HtmlParser], (_htmlParser: HtmlParser) => { htmlParser = _htmlParser; }));

    function preparse(html: string): PreparsedElement {
      return preparseElement(htmlParser.parse(html, 'TestComp').rootNodes[0]);
    }

    it('should detect script elements', inject([HtmlParser], (htmlParser: HtmlParser) => {
         expect(preparse('<script>').type).toBe(PreparsedElementType.SCRIPT);
       }));

    it('should detect style elements', inject([HtmlParser], (htmlParser: HtmlParser) => {
         expect(preparse('<style>').type).toBe(PreparsedElementType.STYLE);
       }));

    it('should detect stylesheet elements', inject([HtmlParser], (htmlParser: HtmlParser) => {
         expect(preparse('<link rel="stylesheet">').type).toBe(PreparsedElementType.STYLESHEET);
         expect(preparse('<link rel="stylesheet" href="someUrl">').hrefAttr).toEqual('someUrl');
         expect(preparse('<link rel="someRel">').type).toBe(PreparsedElementType.OTHER);
       }));

    it('should detect ng-content elements', inject([HtmlParser], (htmlParser: HtmlParser) => {
         expect(preparse('<ng-content>').type).toBe(PreparsedElementType.NG_CONTENT);
       }));

    it('should normalize ng-content.select attribute',
       inject([HtmlParser], (htmlParser: HtmlParser) => {
         expect(preparse('<ng-content>').selectAttr).toEqual('*');
         expect(preparse('<ng-content select>').selectAttr).toEqual('*');
         expect(preparse('<ng-content select="*">').selectAttr).toEqual('*');
       }));

    it('should extract ngProjectAs value', () => {
      expect(preparse('<p ngProjectAs="el[attr].class"></p>').projectAs).toEqual('el[attr].class');
    });
  });
開發者ID:1186792881,項目名稱:angular,代碼行數:37,代碼來源:template_preparser_spec.ts


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