• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript test_lib.inject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中angular2/test_lib.inject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript inject函数的具体用法?TypeScript inject怎么用?TypeScript inject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了inject函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: describe

  describe('file reporter', () => {
    var loggedFile;

    function createReporter({sampleId, descriptions, metrics, path}) {
      var bindings = [
        JsonFileReporter.BINDINGS,
        bind(SampleDescription).toValue(new SampleDescription(sampleId, descriptions, metrics)),
        bind(JsonFileReporter.PATH).toValue(path),
        bind(Options.NOW).toValue(() => DateWrapper.fromMillis(1234)),
        bind(Options.WRITE_FILE)
            .toValue((filename, content) => {
              loggedFile = {'filename': filename, 'content': content};
              return PromiseWrapper.resolve(null);
            })
      ];
      return Injector.resolveAndCreate(bindings).get(JsonFileReporter);
    }

    it('should write all data into a file', inject([AsyncTestCompleter], (async) => {
         createReporter({
           sampleId: 'someId',
           descriptions: [{'a': 2}],
           path: 'somePath',
           metrics: {'script': 'script time'}
         })
             .reportSample([mv(0, 0, {'a': 3, 'b': 6})],
                           [mv(0, 0, {'a': 3, 'b': 6}), mv(1, 1, {'a': 5, 'b': 9})]);
         var regExp = RegExpWrapper.create('somePath/someId_\\d+\\.json');
         expect(isPresent(RegExpWrapper.firstMatch(regExp, loggedFile['filename']))).toBe(true);
         var parsedContent = Json.parse(loggedFile['content']);
         expect(parsedContent)
             .toEqual({
               "description":
                   {"id": "someId", "description": {"a": 2}, "metrics": {"script": "script time"}},
               "completeSample": [
                 {
                   "timeStamp": "1970-01-01T00:00:00.000Z",
                   "runIndex": 0,
                   "values": {"a": 3, "b": 6}
                 }
               ],
               "validSample": [
                 {
                   "timeStamp": "1970-01-01T00:00:00.000Z",
                   "runIndex": 0,
                   "values": {"a": 3, "b": 6}
                 },
                 {
                   "timeStamp": "1970-01-01T00:00:00.001Z",
                   "runIndex": 1,
                   "values": {"a": 5, "b": 9}
                 }
               ]
             });
         async.done();
       }));

  });
开发者ID:AsherBarak,项目名称:angular,代码行数:58,代码来源:json_file_reporter_spec.ts


示例2: describe

 describe('call ProtoViewFactory', () => {
   it('should pass the render protoView', inject([AsyncTestCompleter], (async) => {
     tplResolver.setTemplate(MainComponent, new Template({inline: '<div></div>'}));
     var renderProtoView = createRenderProtoView();
     var expectedProtoView = createProtoView();
     var compiler = createCompiler([renderProtoView], [expectedProtoView]);
     compiler.compile(MainComponent).then((protoView) => {
       var request = protoViewFactory.requests[0];
       expect(request[1]).toBe(renderProtoView);
       async.done();
     });
   }));
   it('should pass the component annotation', inject([AsyncTestCompleter], (async) => {
     tplResolver.setTemplate(MainComponent, new Template({inline: '<div></div>'}));
     var compiler = createCompiler([createRenderProtoView()], [createProtoView()]);
     compiler.compile(MainComponent).then((protoView) => {
       var request = protoViewFactory.requests[0];
       expect(request[0]).toEqual(new Component({selector: 'main-comp'}));
       async.done();
     });
   }));
   it('should pass the directive bindings', inject([AsyncTestCompleter], (async) => {
     tplResolver.setTemplate(MainComponent, new Template({
       inline: '<div></div>',
       directives: [SomeDecoratorDirective]
     }));
     var compiler = createCompiler([createRenderProtoView()], [createProtoView()]);
     compiler.compile(MainComponent).then((protoView) => {
       var request = protoViewFactory.requests[0];
       var binding = request[2][0];
       expect(binding.key.token).toBe(SomeDecoratorDirective);
       async.done();
     });
   }));
   it('should use the protoView of the ProtoViewFactory', inject([AsyncTestCompleter], (async) => {
     tplResolver.setTemplate(MainComponent, new Template({inline: '<div></div>'}));
     var renderProtoView = createRenderProtoView();
     var expectedProtoView = createProtoView();
     var compiler = createCompiler([renderProtoView], [expectedProtoView]);
     compiler.compile(MainComponent).then((protoView) => {
       expect(protoView).toBe(expectedProtoView);
       async.done();
     });
   }));
 });
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:45,代码来源:compiler_spec.ts


示例3: describe

  describe('WebDriverExtension.bindTo', () => {

    it('should bind the extension that matches the capabilities',
       inject([AsyncTestCompleter], (async) => {
         createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'})
             .then((m) => {
               expect(m.id).toEqual('m2');
               async.done();
             });
       }));

    it('should throw if there is no match', inject([AsyncTestCompleter], (async) => {
         PromiseWrapper.catchError(createExtension(['m1'], {'browser': 'm2'}), (err) => {
           expect(isPresent(err)).toBe(true);
           async.done();
         });
       }));
  });
开发者ID:cedriclam,项目名称:angular,代码行数:18,代码来源:web_driver_extension_spec.ts


示例4: describe

  describe('Location', () => {

    var browserLocation, location;

    function makeLocation(baseHref: string = '/my/app', binding: any = CONST_EXPR([])): Location {
      browserLocation = new DummyBrowserLocation();
      browserLocation.internalBaseHref = baseHref;
      let injector = Injector.resolveAndCreate(
          [Location, bind(BrowserLocation).toValue(browserLocation), binding]);
      return location = injector.get(Location);
    }

    beforeEach(makeLocation);

    it('should normalize relative urls on navigate', () => {
      location.go('user/btford');
      expect(browserLocation.path()).toEqual('/my/app/user/btford');
    });

    it('should not prepend urls with starting slash when an empty URL is provided',
       () => { expect(location.normalizeAbsolutely('')).toEqual(browserLocation.getBaseHref()); });

    it('should not prepend path with an extra slash when a baseHref has a trailing slash', () => {
      let location = makeLocation('/my/slashed/app/');
      expect(location.normalizeAbsolutely('/page')).toEqual('/my/slashed/app/page');
    });

    it('should not append urls with leading slash on navigate', () => {
      location.go('/my/app/user/btford');
      expect(browserLocation.path()).toEqual('/my/app/user/btford');
    });

    it('should remove index.html from base href', () => {
      let location = makeLocation('/my/app/index.html');
      location.go('user/btford');
      expect(browserLocation.path()).toEqual('/my/app/user/btford');
    });

    it('should normalize urls on popstate', inject([AsyncTestCompleter], (async) => {
         browserLocation.simulatePopState('/my/app/user/btford');
         location.subscribe((ev) => {
           expect(ev['url']).toEqual('/user/btford');
           async.done();
         })
       }));

    it('should normalize location path', () => {
      browserLocation.internalPath = '/my/app/user/btford';
      expect(location.path()).toEqual('/user/btford');
    });

    it('should use optional base href param', () => {
      let location = makeLocation('/', bind(appBaseHrefToken).toValue('/my/custom/href'));
      location.go('user/btford');
      expect(browserLocation.path()).toEqual('/my/custom/href/user/btford');
    });
  });
开发者ID:AsherBarak,项目名称:angular,代码行数:57,代码来源:location_spec.ts


示例5: describe

 describe('switch value changes', () => {
   it('should switch amongst when values', inject([TestBed, AsyncTestCompleter], (tb, async) => {
     var template = '<div>' + '<ul [switch]="switchValue">' + '<template [switch-when]="\'a\'"><li>when a</li></template>' + '<template [switch-when]="\'b\'"><li>when b</li></template>' + '</ul></div>';
     tb.createView(TestComponent, {html: template}).then((view) => {
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('');
       view.context.switchValue = 'a';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when a');
       view.context.switchValue = 'b';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when b');
       async.done();
     });
   }));
   it('should switch amongst when values with fallback to default', inject([TestBed, AsyncTestCompleter], (tb, async) => {
     var template = '<div>' + '<ul [switch]="switchValue">' + '<li template="switch-when \'a\'">when a</li>' + '<li template="switch-default">when default</li>' + '</ul></div>';
     tb.createView(TestComponent, {html: template}).then((view) => {
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when default');
       view.context.switchValue = 'a';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when a');
       view.context.switchValue = 'b';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when default');
       async.done();
     });
   }));
   it('should support multiple whens with the same value', inject([TestBed, AsyncTestCompleter], (tb, async) => {
     var template = '<div>' + '<ul [switch]="switchValue">' + '<template [switch-when]="\'a\'"><li>when a1;</li></template>' + '<template [switch-when]="\'b\'"><li>when b1;</li></template>' + '<template [switch-when]="\'a\'"><li>when a2;</li></template>' + '<template [switch-when]="\'b\'"><li>when b2;</li></template>' + '<template [switch-default]><li>when default1;</li></template>' + '<template [switch-default]><li>when default2;</li></template>' + '</ul></div>';
     tb.createView(TestComponent, {html: template}).then((view) => {
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when default1;when default2;');
       view.context.switchValue = 'a';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when a1;when a2;');
       view.context.switchValue = 'b';
       view.detectChanges();
       expect(DOM.getText(view.nodes[0])).toEqual('when b1;when b2;');
       async.done();
     });
   }));
 });
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:44,代码来源:switch_spec.ts


示例6: describe

 describe("valueChanges", () => {
   var a,
       c1,
       c2;
   beforeEach(() => {
     c1 = new Control("old1");
     c2 = new Control("old2");
     a = new ControlArray([c1, c2]);
   });
   it("should fire an event after the value has been updated", inject([AsyncTestCompleter], (async) => {
     ObservableWrapper.subscribe(a.valueChanges, (value) => {
       expect(a.value).toEqual(['new1', 'old2']);
       expect(value).toEqual(['new1', 'old2']);
       async.done();
     });
     c1.updateValue("new1");
   }));
   it("should fire an event after the control's observable fired an event", inject([AsyncTestCompleter], (async) => {
     var controlCallbackIsCalled = false;
     ObservableWrapper.subscribe(c1.valueChanges, (value) => {
       controlCallbackIsCalled = true;
     });
     ObservableWrapper.subscribe(a.valueChanges, (value) => {
       expect(controlCallbackIsCalled).toBe(true);
       async.done();
     });
     c1.updateValue("new1");
   }));
   it("should fire an event when a control is removed", inject([AsyncTestCompleter], (async) => {
     ObservableWrapper.subscribe(a.valueChanges, (value) => {
       expect(value).toEqual(['old1']);
       async.done();
     });
     a.removeAt(1);
   }));
   it("should fire an event when a control is added", inject([AsyncTestCompleter], (async) => {
     a.removeAt(1);
     ObservableWrapper.subscribe(a.valueChanges, (value) => {
       expect(value).toEqual(['old1', 'old2']);
       async.done();
     });
     a.push(c2);
   }));
 });
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:44,代码来源:model_spec.ts


示例7: describe

 describe('.head()', () => {
   it('should perform a head request for given url', inject([AsyncTestCompleter], async => {
        ObservableWrapper.subscribe(backend.connections, c => {
          expect(c.request.method).toBe(RequestMethods.HEAD);
          backend.resolveAllConnections();
          async.done();
        });
        ObservableWrapper.subscribe(http.head(url), res => {});
      }));
 });
开发者ID:cedriclam,项目名称:angular,代码行数:10,代码来源:http_spec.ts


示例8: describe

 describe('.delete()', () => {
   it('should perform a delete request for given url', inject([AsyncTestCompleter], async => {
        backend.connections.subscribe((c) => {
          expect(c.request.method).toBe(RequestMethods.DELETE);
          backend.resolveAllConnections();
          async.done();
        });
        http.delete(url).subscribe(res => {});
      }));
 });
开发者ID:AsherBarak,项目名称:angular,代码行数:10,代码来源:http_spec.ts


示例9: describe

      describe('frame metrics', () => {
        it('should report ImplThreadRenderingStats as frame event',
           inject([AsyncTestCompleter], (async) => {
             createExtension([
               benchmarkEvents.instant('BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
                                       {'data': {'frame_count': 1}})
             ])
                 .readPerfLog()
                 .then((events) => {
                   expect(events).toEqual([
                     normEvents.create('i', 'frame', 1.1),
                   ]);
                   async.done();
                 });
           }));

        it('should not report ImplThreadRenderingStats with zero frames',
           inject([AsyncTestCompleter], (async) => {
             createExtension([
               benchmarkEvents.instant('BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
                                       {'data': {'frame_count': 0}})
             ])
                 .readPerfLog()
                 .then((events) => {
                   expect(events).toEqual([]);
                   async.done();
                 });
           }));

        it('should throw when ImplThreadRenderingStats contains more than one frame',
           inject([AsyncTestCompleter], (async) => {
             PromiseWrapper.catchError(
                 createExtension([
                   benchmarkEvents.instant('BenchmarkInstrumentation::ImplThreadRenderingStats',
                                           1100, {'data': {'frame_count': 2}})
                 ]).readPerfLog(),
                 (err) => {
                   expect(() => { throw err; })
                       .toThrowError('multi-frame render stats not supported');
                   async.done();
                 });
           }));
      });
开发者ID:AsherBarak,项目名称:angular,代码行数:43,代码来源:chrome_driver_extension_spec.ts


示例10: describe

    describe('css', () => {
      it('should load inline styles', inject([AsyncTestCompleter], (async) => {
           var template = new ViewDefinition({template: 'html', styles: ['style 1', 'style 2']});
           loader.load(template).then((el) => {
             expect(DOM.getInnerHTML(el))
                 .toEqual(
                     '<style type="text/css">style 1</style><style type="text/css">style 2</style>html');
             async.done();
           });
         }));

      it('should load templates through XHR', inject([AsyncTestCompleter], (async) => {
           xhr.expect('base/foo.html', 'xhr template');
           xhr.expect('base/foo-1.css', '1');
           xhr.expect('base/foo-2.css', '2');
           var template = new ViewDefinition({
             templateAbsUrl: 'base/foo.html',
             styles: ['i1'],
             styleAbsUrls: ['base/foo-1.css', 'base/foo-2.css']
           });
           loader.load(template).then((el) => {
             expect(DOM.getInnerHTML(el))
                 .toEqual(
                     '<style type="text/css">i1</style><style type="text/css">1</style><style type="text/css">2</style>xhr template');
             async.done();
           });
           xhr.flush();
         }));

      it('should return a rejected Promise when XHR loading fails',
         inject([AsyncTestCompleter], (async) => {
           xhr.expect('base/foo.css', null);
           var template = new ViewDefinition({template: '', styleAbsUrls: ['base/foo.css']});
           PromiseWrapper.then(loader.load(template), function(_) { throw 'Unexpected response'; },
                               function(error) {
                                 expect(error.message)
                                     .toEqual('Failed to fetch url "base/foo.css"');
                                 async.done();
                               });
           xhr.flush();
         }));
    });
开发者ID:AsherBarak,项目名称:angular,代码行数:42,代码来源:template_loader_spec.ts



注:本文中的angular2/test_lib.inject函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript test_lib.inspectNativeElement函数代码示例发布时间:2022-05-25
下一篇:
TypeScript test_lib.flushMicrotasks函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap