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


TypeScript fetch-mock.reMock函数代码示例

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


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

示例1:

        return Promise.all(_.map(tableList, (id: TableID) => {
          let response: TableDetailsResponseMessage;

          fetchMock.reMock(re, "get", (url: string, requestObj: RequestInit) => {
            let result = url.match(re);
            let database = result[1];
            let table = result[2];

            assert.deepEqual(state.databaseInfo.tableDetails[databases.generateTableID(id.db, id.table)], { inFlight: true, valid: false });

            response = new protos.cockroach.server.serverpb.TableDetailsResponse(dbTables[databases.generateTableID(database, table)]);

            return {
              sendAsJson: false,
              body: response.toArrayBuffer(),
            };
          });

          return databases.refreshTableDetails(id.db, id.table)(dispatch, () => state).then(() => {
            let generatedID = databases.generateTableID(id.db, id.table);
            assert.deepEqual(state.databaseInfo.tableDetails[generatedID].data, new protos.cockroach.server.serverpb.TableDetailsResponse(dbTables[id.db][id.table]));
            assert.deepEqual(state.databaseInfo.tableDetails[generatedID], {
              inFlight: false,
              valid: true,
              data: response,
              lastError: null,
            });
          });
        }));
开发者ID:CubeLite,项目名称:cockroach,代码行数:29,代码来源:databaseInfo.spec.ts

示例2: RegExp

        return Promise.all(_.map(tableList, (id: TableID) => {
          fetchMock.reMock(new RegExp("/_admin/v1/databases/.+/tables/.+"), "get", (url: string, requestObj: RequestInit) => {
            assert.deepEqual(state.databaseInfo.tableDetails[databases.generateTableID(id.db, id.table)], { inFlight: true, valid: false });

            return { throws: error };
          });

          return databases.refreshTableDetails(id.db, id.table)(dispatch, () => state).then(() => {
            let generatedID = databases.generateTableID(id.db, id.table);
            assert.deepEqual(state.databaseInfo.tableDetails[generatedID], {
              inFlight: false,
              valid: false,
              lastError: error,
            });
          });
        }));
开发者ID:CubeLite,项目名称:cockroach,代码行数:16,代码来源:databaseInfo.spec.ts

示例3:

fetchMock.mock("http://test.com", 200);
fetchMock.mock(/test\.com/, 200);
fetchMock.mock(() => true, 200);
fetchMock.mock((url, opts) => true, 200);

fetchMock.mock(/test/, "test").mock(/test/, { a: "b" });
fetchMock.mock(/test/, {
    status: 200,
    headers: {
        "test": "test"
    },
    body: {
        a: "b"
    }
});

fetchMock.reMock();

fetchMock.restore().reset();

fetchMock.calls().matched[0][1].body;
fetchMock.calls().unmatched[0][0].toUpperCase();
fetchMock.calls("http://test.com")[0][0].toUpperCase();
fetchMock.calls("http://test.com")[0][1].body;

fetchMock.called("http://test.com");

fetchMock.lastCall()[1].body;
fetchMock.lastUrl();
fetchMock.lastOptions();
开发者ID:ASnow,项目名称:DefinitelyTyped,代码行数:30,代码来源:fetch-mock-tests.ts


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