本文整理汇总了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,
});
});
}));
示例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,
});
});
}));
示例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();