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


TypeScript moxios.wait函數代碼示例

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


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

示例1: it

      it('POSTs to Circle for env-vars beginning with "DEPLOY_VAR_"', (done: MochaDone) => {
        const api = new Circle("test", "test", "");
        moxios.stubOnce(
          "POST",
          `/project/github/test/test/envvar?circle-token=llama`,
          {
            status: 200,
            response: {
              LLAMA: "duck"
            }
          }
        );

        const resultsPromise = api.addEnvVars("test", "test", {
          DEPLOY_VAR_HERPA: "derpa",
          DEPLOY_VAR_LLAMA: "duck"
        });

        moxios.wait(async () => {
          const results = await resultsPromise;
          const firstRequest = moxios.requests.at(0);
          const secondRequest = moxios.requests.at(1);

          // @TODO uncomment after DefinitelyTyped#20466 fixed
          // JSON.parse(firstRequest.config.data).name.should.equal('HERPA');
          // JSON.parse(firstRequest.config.data).value.should.equal('derpa');
          // JSON.parse(secondRequest.config.data).name.should.equal('LLAMA');
          // JSON.parse(secondRequest.config.data).value.should.equal('duck');

          done();
        });
      });
開發者ID:ft-interactive,項目名稱:ft-ig-github-project-manager,代碼行數:32,代碼來源:Circle.spec.ts

示例2: it

            it('Should stub and find multiple requests by method', (done) => {
                moxios.stubOnce('PUT', '/users/12345', {
                    status: 204
                });

                moxios.stubOnce('GET', '/users/12346', {
                    status: 200,
                    response: USER_FRED
                });

                axios.put('/users/12345', USER_FRED).then(onFulfilled);
                axios.get('/users/12346', {}).then(onFulfilled);

                moxios.wait(() => {
                    equal(onFulfilled.calledTwice, true);

                    let response1 = onFulfilled.getCall(0).args[0];
                    let response2 = onFulfilled.getCall(1).args[0];
                    equal(response1.status, 204);
                    equal(response2.status, 200);
                    equal(response2.data.firstName, 'Fred');

                    let request = moxios.requests.get('PUT', '/users/12345');
                    notEqual(request, undefined);

                    request = moxios.requests.get('GET', '/users/12346');
                    notEqual(request, undefined);

                    done();
                });
            });
開發者ID:Crevil,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:moxios-tests.ts

示例3: equal

            moxios.withMock(() => {
                axios.get('/users/12345');

                moxios.wait(() => {
                    let request = moxios.requests.mostRecent();
                    request.respondWithTimeout().catch((err: any) => {
                        equal(err.code, 'ECONNABORTED');
                        done();
                    });
                });
            });
開發者ID:Crevil,項目名稱:DefinitelyTyped,代碼行數:11,代碼來源:moxios-tests.ts

示例4: it

 it("fails to delete a Regimen", (done) => {
     let spy = jasmine.createSpy("delete_fail");
     let thunk = deleteRegimen(regimen);
     spyOn(toast, "error");
     let response = { id: 1, firstName: "Fred", lastName: "Flintstone" };
     thunk(spy);
     moxios
         .wait(() => {
             let request = moxios.requests.mostRecent();
             request
                 .respondWith({ status: 404, response })
                 .then(function () {
                     expect(toast.error)
                         .toHaveBeenCalledWith("Unable to delete regimen.");
                     done();
                 });
         });
 });
開發者ID:roryaronson,項目名稱:farmbot-web-frontend,代碼行數:18,代碼來源:actions_spec.ts

示例5: it

 it("cancels the account", (done) => {
   expect.assertions(2);
   API.setBaseUrl("http://example.com:80");
   let thunk = deleteUser({ password: "Foo!" });
   let dispatch = jest.fn();
   let getState = jest.fn();
   getState.mockImplementation(() => ({ auth: {} }));
   thunk(dispatch, getState);
   moxios.wait(function () {
     let request = moxios.requests.mostRecent();
     request.respondWith({
       status: 200,
       response: {}
     }).then(function (resp) {
       expect(resp.config.url).toContain("api/users");
       expect(resp.config.method).toBe("delete");
       done();
     });
   });
 });
開發者ID:MrChristofferson,項目名稱:Farmbot-Web-API,代碼行數:20,代碼來源:actions_test.ts

示例6: it

  it("errors while resetting an account", (done) => {
    expect.assertions(3);
    API.setBaseUrl("http://example.com:80");
    const thunk = resetAccount({ password: "not Foo!" });
    const dispatch = jest.fn();
    const getState = jest.fn();
    getState.mockImplementation(() => ({ auth: {} }));
    window.alert = jest.fn();
    thunk(dispatch, getState);

    moxios.wait(function () {
      const request = moxios.requests.mostRecent();
      request.respondWith({
        status: 422,
        response: {}
      }).then(resp => {
        expect(window.alert).not.toHaveBeenCalled();
        expect(toastErrors).toHaveBeenCalled();
        expect(resp.config.url).toContain("api/device/reset");
        done();
      });
    });
  });
開發者ID:FarmBot,項目名稱:Farmbot-Web-API,代碼行數:23,代碼來源:actions_test.ts


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