当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript test_lib.fakeAsync函数代码示例

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


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

示例1: describe

      describe("updateValue", () => {
        var g, c;
        beforeEach(() => {
          c = new Control("oldValue");
          g = new ControlGroup({"one": c});
        });

        it("should update the value of the control", () => {
          c.updateValue("newValue");
          expect(c.value).toEqual("newValue");
        });

        it("should invoke onChange if it is present", () => {
          var onChange;
          c.registerOnChange((v) => onChange = ["invoked", v]);

          c.updateValue("newValue");

          expect(onChange).toEqual(["invoked", "newValue"]);
        });

        it("should not invoke on change when explicitly specified", () => {
          var onChange = null;
          c.registerOnChange((v) => onChange = ["invoked", v]);

          c.updateValue("newValue", {emitModelToViewChange: false});

          expect(onChange).toBeNull();
        });

        it("should update the parent", () => {
          c.updateValue("newValue");
          expect(g.value).toEqual({"one": "newValue"});
        });

        it("should not update the parent when explicitly specified", () => {
          c.updateValue("newValue", {onlySelf: true});
          expect(g.value).toEqual({"one": "oldValue"});
        });

        it("should fire an event", fakeAsync(() => {
             ObservableWrapper.subscribe(c.valueChanges,
                                         (value) => { expect(value).toEqual("newValue"); });

             c.updateValue("newValue");
             tick();
           }));

        it("should not fire an event when explicitly specified", fakeAsync(() => {
             ObservableWrapper.subscribe(c.valueChanges, (value) => { throw "Should not happen"; });

             c.updateValue("newValue", {emitEvent: false});

             tick();
           }));
      });
开发者ID:goderbauer,项目名称:angular,代码行数:56,代码来源:model_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:CADBOT,项目名称:angular,代码行数:52,代码来源: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:CADBOT,项目名称:angular,代码行数:7,代码来源:fake_async_spec.ts

示例4: expect

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


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