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

TypeScript testing_internal.fakeAsync函数代码示例

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

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



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

示例1: describe

    describe("composeAsync", () => {
      function asyncValidator(expected, response) {
        return (c) => {
          var emitter = new EventEmitter();
          var res = c.value != expected ? response : null;

          PromiseWrapper.scheduleMicrotask(() => {
            ObservableWrapper.callEmit(emitter, res);
            // this is required because of a bug in ObservableWrapper
            // where callComplete can fire before callEmit
            // remove this one the bug is fixed
            TimerWrapper.setTimeout(() => { ObservableWrapper.callComplete(emitter); }, 0);
          });
          return emitter;
        };
      }

      it("should return null when given null",
         () => { expect(Validators.composeAsync(null)).toEqual(null); });

      it("should collect errors from all the validators", fakeAsync(() => {
           var c = Validators.composeAsync([
             asyncValidator("expected", {"one": true}),
             asyncValidator("expected", {"two": true})
           ]);

           var value = null;
           c(new Control("invalid")).then(v => value = v);

           tick(1);

           expect(value).toEqual({"one": true, "two": true});
         }));

      it("should return null when no errors", fakeAsync(() => {
           var c = Validators.composeAsync([asyncValidator("expected", {"one": true})]);

           var value = null;
           c(new Control("expected")).then(v => value = v);

           tick(1);

           expect(value).toEqual(null);
         }));

      it("should ignore nulls", fakeAsync(() => {
           var c = Validators.composeAsync([asyncValidator("expected", {"one": true}), null]);

           var value = null;
           c(new Control("invalid")).then(v => value = v);

           tick(1);

           expect(value).toEqual({"one": true});
         }));
    });
开发者ID:Ashok-Pal,项目名称:angular,代码行数:56,代码来源:validators_spec.ts


示例2: describe

    describe('Promise', () => {
      it('should run asynchronous code', fakeAsync(() => {
           var thenRan = false;
           PromiseWrapper.resolve(null).then((_) => { thenRan = true; });

           expect(thenRan).toEqual(false);

           flushMicrotasks();
           expect(thenRan).toEqual(true);
         }));

      it('should run chained thens', fakeAsync(() => {
           var log = new Log();

           PromiseWrapper.resolve(null).then((_) => log.add(1)).then((_) => log.add(2));

           expect(log.result()).toEqual('');

           flushMicrotasks();
           expect(log.result()).toEqual('1; 2');
         }));

      it('should run Promise created in Promise', fakeAsync(() => {
           var log = new Log();

           PromiseWrapper.resolve(null).then((_) => {
             log.add(1);
             PromiseWrapper.resolve(null).then((_) => log.add(2));
           });

           expect(log.result()).toEqual('');

           flushMicrotasks();
           expect(log.result()).toEqual('1; 2');
         }));

      // TODO(vicb): check why this doesn't work in JS - linked to open issues on GH ?
      xit('should complain if the test throws an exception during async calls', () => {
        expect(() => {
          fakeAsync(() => {
            PromiseWrapper.resolve(null).then((_) => { throw new BaseException('async'); });
            flushMicrotasks();
          })();
        }).toThrowError('async');
      });

      it('should complain if a test throws an exception', () => {
        expect(() => {
          fakeAsync(() => { throw new BaseException('sync'); })();
        }).toThrowError('sync');
      });

    });
开发者ID:LordBinary,项目名称:angular,代码行数:53,代码来源:fake_async_spec.ts


示例3: it

    it('should flush microtasks before returning', () => {
      var thenRan = false;

      fakeAsync(() => { PromiseWrapper.resolve(null).then(_ => { thenRan = true; }); })();

      expect(thenRan).toEqual(true);
    });
开发者ID:1186792881,项目名称:angular,代码行数:7,代码来源:fake_async_spec.ts


示例4: describe

  describe('CachedXHR', () => {
    var xhr: CachedXHR;

    function createCachedXHR(): CachedXHR {
      setTemplateCache({'test.html': '<div>Hello</div>'});
      return new CachedXHR();
    }
    beforeEachProviders(() => [
      provide(UrlResolver, {useClass: TestUrlResolver}),
      provide(XHR, {useFactory: createCachedXHR})
    ]);

    it('should throw exception if $templateCache is not found', () => {
      setTemplateCache(null);
      expect(() => { xhr = new CachedXHR(); })
          .toThrowErrorWith('CachedXHR: Template cache was not found in $templateCache.');
    });

    it('should resolve the Promise with the cached file content on success',
       inject([AsyncTestCompleter], (async) => {
         setTemplateCache({'test.html': '<div>Hello</div>'});
         xhr = new CachedXHR();
         xhr.get('test.html')
             .then((text) => {
               expect(text).toEqual('<div>Hello</div>');
               async.done();
             });
       }));

    it('should reject the Promise on failure', inject([AsyncTestCompleter], (async) => {
         xhr = new CachedXHR();
         xhr.get('unknown.html')
             .then((text) => { throw new BaseException('Not expected to succeed.'); })
             .catch((error) => { async.done(); });
       }));

    it('should allow fakeAsync Tests to load components with templateUrl synchronously',
       fakeAsync(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
         let fixture: ComponentFixture;
         tcb.createAsync(TestComponent).then((f) => { fixture = f; });

         // This should initialize the fixture.
         tick();

         expect(fixture.debugElement.children[0].nativeElement).toHaveText('Hello');
       })));
  });
开发者ID:844496869,项目名称:angular,代码行数:47,代码来源:xhr_cache_spec.ts


示例5: expect

 expect(() => {
   fakeAsync(() => {
     PromiseWrapper.resolve(null).then((_) => { throw new BaseException('async'); });
     flushMicrotasks();
   })();
 }).toThrowError('async');
开发者ID:1186792881,项目名称:angular,代码行数:6,代码来源:fake_async_spec.ts


示例6: expect

 expect(() => {
   fakeAsync(() => { TimerWrapper.setInterval(() => {}, 10); })();
 }).toThrowError('1 periodic timer(s) still in the queue.');
开发者ID:LordBinary,项目名称:angular,代码行数:3,代码来源:fake_async_spec.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript testing_internal.flushMicrotasks函数代码示例发布时间:2022-05-25
下一篇:
TypeScript testing_internal.el函数代码示例发布时间: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