當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。