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


TypeScript TestSupport.wait_for_promise函數代碼示例

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


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

示例1: it

        it('correctly invalidates cache and does not fetch', () => {
          const resource = new Resource(schema.users);
          const store = schema.__node.definition.storeMap.getOrCreate('user');
          spy(store, 'invalidate');

          return wait_for_promise(() => resource.status === IStatus.complete)
            .then(() => {
              expect(mock_request_count()).to.equal(1);

              resource.invalidate({ foo: 123, noFetchGet: true });

              expect(store.invalidate.callCount).to.equal(1);
              expect(store.invalidate.getCall(0).args[1]).to.deep.equal({
                foo: 123,
                noFetchGet: true,
                invoker: resource
              });
              expect(resource.status).to.equal(IStatus.stale);
              expect(resource.timestamp).to.equal(ITimestamp.stale);
              expect(mock_request_count()).to.equal(1);
            })
            .then(delay_for())
            .then(() => {
              // no request occurs after invalidating
              expect(mock_request_count()).to.equal(1);
              expect(resource.status).to.equal(IStatus.stale);
              expect(resource.timestamp).to.equal(ITimestamp.stale);
            });
        });
開發者ID:netarc,項目名稱:refrax,代碼行數:29,代碼來源:resource.spec.ts

示例2: expect

              .then(() => {
                // prove Resource made no request
                expect(resource.data).to.equal(null);
                expect(resource.status).to.equal(IStatus.stale);
                expect(resource.timestamp).to.equal(ITimestamp.stale);
                expect(mock_request_count()).to.equal(0);
                expect(onLoad.callCount).to.equal(0);
                expect(onChange.callCount).to.equal(0);

                // re-enable fetch get
                resource._options.noFetchGet = false;

                const fragment = resource._fetchFragment();
                expect(fragment).is.instanceof(FragmentResult);
                expect(fragment.data).to.equal(null);
                expect(fragment.status).to.equal(IStatus.stale);
                expect(fragment.timestamp).to.equal(ITimestamp.loading);
                expect(resource.data).to.equal(null);
                expect(resource.status).to.equal(IStatus.stale);
                expect(resource.timestamp).to.equal(ITimestamp.loading);
                expect(onLoad.callCount).to.equal(0);
                expect(onChange.callCount).to.equal(0);

                return wait_for_promise(() => resource.status === IStatus.complete)
                  .then(() => {
                    expect(onLoad.callCount).to.equal(1);
                    expect(onChange.callCount).to.equal(1);
                    expect(mock_request_count()).to.equal(1);
                    expect(resource.data).to.deep.equal(dataCollectionUsers);
                    expect(resource.status).to.equal(IStatus.complete);
                    expect(resource.timestamp).to.not.equal(ITimestamp.loading);
                  });
              });
開發者ID:netarc,項目名稱:refrax,代碼行數:33,代碼來源:resource.spec.ts


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