本文整理匯總了TypeScript中proxyquire.load函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript load函數的具體用法?TypeScript load怎麽用?TypeScript load使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了load函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getDatabaseDetails
return Promise.all(_.map([DB1, DB2], (db: string) => {
let error: Error;
function getDatabaseDetails(req: DatabaseDetailsRequest): Promise<DatabaseDetailsResponseMessage> {
return new Promise((resolve, reject) => {
assert.deepEqual(state.databaseInfo.databaseDetails[req.database], { inFlight: true, valid: false });
error = new Error();
reject(error);
});
}
databasesMocked = proxyquire.load("./databaseInfo", {
"../util/api": {
getDatabaseDetails,
},
});
return databasesMocked.refreshDatabaseDetails(db)(dispatch, () => state).then(() => {
assert.deepEqual(state.databaseInfo.databaseDetails[db], {
inFlight: false,
valid: false,
lastError: error,
});
});
}));
示例2: getTableDetails
return Promise.all(_.map(tableList, (id: TableID) => {
let response: TableDetailsResponse;
function getTableDetails(req: TableDetailsRequest): Promise<TableDetailsResponseMessage> {
return new Promise((resolve, reject) => {
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(req.database, req.table)]);
resolve(response);
});
}
databasesMocked = proxyquire.load("./databaseInfo", {
"../util/api": {
getTableDetails,
},
});
return databasesMocked.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,
});
});
}));
示例3: it
it("handles database list errors", function () {
error = new Error();
function getDatabaseList(): Promise<DatabasesResponseMessage> {
return new Promise((resolve, reject) => {
reject(error);
});
}
databasesMocked = proxyquire.load("./databaseInfo", {
"../util/api": {
getDatabaseList,
},
});
return databasesMocked.refreshDatabases()(dispatch, () => state).then(() => {
assert.deepEqual(state.databaseInfo.databases, { valid: false, inFlight: false, lastError: error });
});
});
示例4: before
import {Store} from "@tsed/core";
import {expect} from "chai";
import * as Proxyquire from "proxyquire";
import * as Sinon from "sinon";
import {AcceptMimesMiddleware} from "../../../../src/mvc";
const middleware: any = Sinon.stub();
const useBeforeStub: any = Sinon.stub().returns(middleware);
const {AcceptMime} = Proxyquire.load("../../../../src/mvc/decorators/method/acceptMime", {
"./useBefore": {UseBefore: useBeforeStub}
});
class Test {
}
describe("AcceptMime", () => {
before(() => {
this.descriptor = {};
this.options = "application/json";
AcceptMime("application/json")(Test, "test", this.descriptor);
this.store = Store.from(Test, "test", this.descriptor);
});
after(() => {
delete this.descriptor;
delete this.options;
});
it("should set metadata", () => {
expect(this.store.get(AcceptMimesMiddleware)).to.deep.eq([this.options]);
示例5: return
import {Store} from "@tsed/core";
import {assert, expect} from "chai";
import * as Proxyquire from "proxyquire";
import * as Sinon from "sinon";
import {FakeRequest, FakeResponse} from "../../../../../../test/helper";
let middleware: any;
const useAfterStub: any = (_middleware_: any) => {
middleware = _middleware_;
return () => {
};
};
const Header = Proxyquire.load("../../../../src/mvc/decorators/method/header", {
"./useAfter": {UseAfter: useAfterStub}
}).Header;
class Test {
}
describe("Header", () => {
describe("when is used as method decorator", () => {
before(() => {
this.request = new FakeRequest();
this.response = new FakeResponse();
Sinon.stub(this.response, "set").returns(this.response);
this.nextSpy = Sinon.spy();
});
after(() => {
示例6: describe
import {assert} from "chai";
import * as Proxyquire from "proxyquire";
import * as Sinon from "sinon";
const middleware: any = Sinon.stub();
const useStub: any = Sinon.stub().returns(middleware);
const {All, Get, Post, Put, Delete, Head, Patch} = Proxyquire.load("../../../../src/mvc/decorators/method/route", {
"./use": {Use: useStub}
});
describe("Route decorators", () => {
describe("All", () => {
before(() => {
this.options = ["/", () => {
}];
All(...this.options);
});
after(() => {
delete this.descriptor;
delete this.options;
});
it("should create middleware", () => {
assert(useStub.calledWith("all", ...this.options[0]));
});
});
describe("Get", () => {
before(() => {
示例7: before
import {Store} from "@tsed/core";
import {expect} from "chai";
import * as Proxyquire from "proxyquire";
import * as Sinon from "sinon";
import {ResponseViewMiddleware} from "../../../../src/mvc";
const middleware: any = Sinon.stub();
const useAfterStub: any = Sinon.stub().returns(middleware);
const {ResponseView} = Proxyquire.load("../../../../src/mvc/decorators/method/responseView", {
"./useAfter": {UseAfter: useAfterStub}
});
class Test {
}
describe("ResponseView", () => {
before(() => {
this.descriptor = {};
this.options = ["page", {}];
ResponseView(...this.options)(Test, "test", this.descriptor);
this.store = Store.from(Test, "test", this.descriptor);
});
after(() => {
delete this.descriptor;
delete this.options;
});
it("should set metadata", () => {
expect(this.store.get(ResponseViewMiddleware)).to.deep.eq({
viewPath: this.options[0],