本文整理汇总了TypeScript中mocks/node-modules/angular/types.QMock.promisify方法的典型用法代码示例。如果您正苦于以下问题:TypeScript QMock.promisify方法的具体用法?TypeScript QMock.promisify怎么用?TypeScript QMock.promisify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mocks/node-modules/angular/types.QMock
的用法示例。
在下文中一共展示了QMock.promisify方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
public constructor(categoryMockProvider: CategoryMockProvider, categoriesMockProvider: CategoriesMockProvider, $qMockProvider: QMockProvider) {
// Success/error = options for the stub promises
const success: PromiseMockConfig<{data: Category}> = {
args: {id: 1},
response: {data: categoryMockProvider.$get()}
},
error: PromiseMockConfig<void> = {
args: {id: -1}
},
$q: QMock = $qMockProvider.$get();
// Mock categoryModel object
this.categoryModel = {
recent: "recent categories list",
type: "category",
path(id: number): string {
return `/categories/${id}`;
},
all: $q.promisify({
response: categoriesMockProvider.$get()
}),
allWithChildren: sinon.stub().returns(categoriesMockProvider.$get()),
find(id: number): SinonStub {
let category: Category;
// Get the matching category
if (id < 10) {
category = categoriesMockProvider.$get()[id - 1];
} else {
const parentId: number = (id / 10) - 1,
childId: number = id % 10;
category = (categoriesMockProvider.$get()[parentId].children as Category[])[childId];
}
// Return a promise-like object that resolves with the category
return $q.promisify({response: category})();
},
save: $q.promisify(success, error),
destroy: $q.promisify(success, error),
toggleFavourite(category: Category): SinonStub {
return $q.promisify({response: !category.favourite})();
},
flush: sinon.stub(),
addRecent: sinon.stub()
};
// Spy on find() and toggleFavourite()
sinon.spy(this.categoryModel, "find");
sinon.spy(this.categoryModel, "toggleFavourite");
}
示例2: constructor
public constructor(scheduleMockProvider: ScheduleMockProvider, schedulesMockProvider: SchedulesMockProvider, $qMockProvider: QMockProvider) {
// Success/error = options for the stub promises
const success: PromiseMockConfig<ScheduledTransferTransaction> = {
args: {id: 1},
response: scheduleMockProvider.$get()
},
error: PromiseMockConfig<void> = {
args: {id: -1}
},
$q: QMock = $qMockProvider.$get();
// Mock scheduleModel object
this.scheduleModel = {
all: sinon.stub().returns(schedulesMockProvider.$get()),
save: $q.promisify(success, error),
destroy: $q.promisify(success, error)
};
}
示例3: constructor
public constructor($qMockProvider: QMockProvider) {
const $q: QMock = $qMockProvider.$get();
// Mock authenticationModel object
this.authenticationModel = {
login: $q.promisify("gooduser", "baduser"),
logout: sinon.stub(),
isAuthenticated: true
};
}
示例4: constructor
public constructor(transactionMockProvider: TransactionMockProvider, transactionBatchMockProvider: TransactionBatchMockProvider, $qMockProvider: QMockProvider) {
// Success/error = options for the stub promises
const success: PromiseMockConfig<BasicTransaction> = {
args: {id: 1},
response: transactionMockProvider.$get()
},
error: PromiseMockConfig<void> = {
args: {id: -1}
},
$q: QMock = $qMockProvider.$get();
// Mock transactionModel object
this.transactionModel = {
all: $q.promisify({
args: "/1",
response: transactionBatchMockProvider.$get()
}, {
args: "/-1"
}),
query: $q.promisify({
args: "search",
response: transactionBatchMockProvider.$get()
}, {
args: "dontsearch"
}),
findSubtransactions: $q.promisify({
response: [
createSubtransferTransaction({id: 1}),
createSubtransaction({id: 2}),
createSubtransaction({id: 3})
]
}, {
args: -1
}),
find: $q.promisify({
response: transactionMockProvider.$get()
}),
save: $q.promisify(success, error),
destroy: $q.promisify(success, error),
updateStatus: $q.promisify(),
flag: $q.promisify(success, error),
unflag: $q.promisify(1, -1),
allDetailsShown: sinon.stub().returns(true),
showAllDetails: sinon.stub(),
lastTransactionDate: startOfDay(new Date())
};
}
示例5: constructor
public constructor(accountMockProvider: AccountMockProvider, accountsMockProvider: AccountsMockProvider, accountsWithBalancesMockProvider: AccountsWithBalancesMockProvider, $qMockProvider: QMockProvider) {
/*
* Success/error = options for the stub promises
* all/allWithBalances = promise-like responses
*/
const success: PromiseMockConfig<{data: Account}> = {
args: {id: 1},
response: {data: accountMockProvider.$get()}
},
error: PromiseMockConfig<void> = {
args: {id: -1}
},
$q: QMock = $qMockProvider.$get(),
all: SinonStub = $q.promisify({
response: accountsMockProvider.$get()
}),
allWithBalances: SinonStub = $q.promisify({
response: accountsWithBalancesMockProvider.$get()
});
// Configure the different responses for all()
all.withArgs(true).returns(allWithBalances());
// Mock accountModel object
this.accountModel = {
recent: "recent accounts list",
type: "account",
path(id: number): string {
return `/accounts/${id}`;
},
all: sinon.stub().returns(all()),
allWithBalances: sinon.stub().returns(all(true)),
find(id: number): SinonStub {
// Get the matching account
const account: Account = accountsMockProvider.$get()[id - 1];
// Return a promise-like object that resolves with the account
return $q.promisify({response: account})();
},
save: $q.promisify(success, error),
destroy: $q.promisify(success, error),
reconcile: $q.promisify(),
toggleFavourite(account: Account): SinonStub {
return $q.promisify({response: !account.favourite})();
},
isUnreconciledOnly: sinon.stub().returns(true),
unreconciledOnly: sinon.stub(),
flush: sinon.stub(),
addRecent: sinon.stub(),
accounts: accountsWithBalancesMockProvider.$get()
};
// Spy on find() and toggleFavourite()
sinon.spy(this.accountModel, "find");
sinon.spy(this.accountModel, "toggleFavourite");
}
示例6: constructor
public constructor(payeeMockProvider: PayeeMockProvider, payeesMockProvider: PayeesMockProvider, $qMockProvider: QMockProvider) {
// Success/error = options for the stub promises
const success: PromiseMockConfig<{data: Payee}> = {
args: {id: 1},
response: {data: payeeMockProvider.$get()}
},
error: PromiseMockConfig<void> = {
args: {id: -1}
},
$q: QMock = $qMockProvider.$get();
// Mock payeeModel object
this.payeeModel = {
recent: "recent payees list",
type: "payee",
path(id: number): string {
return `/payees/${id}`;
},
all: $q.promisify({response: payeesMockProvider.$get()}),
allList: $q.promisify({response: payeesMockProvider.$get()}),
find(id: number): SinonStub {
// Get the matching payee
const payee: Payee = payeesMockProvider.$get()[id - 1];
// Return a promise-like object that resolves with the payee
return $q.promisify({response: payee})();
},
findLastTransaction: $q.promisify({response: {}}, {args: -1}),
save: $q.promisify(success, error),
destroy: $q.promisify(success, error),
toggleFavourite(payee: Payee): SinonStub {
return $q.promisify({response: !payee.favourite})();
},
flush: sinon.stub(),
addRecent: sinon.stub()
};
// Spy on find() and toggleFavourite()
sinon.spy(this.payeeModel, "find");
sinon.spy(this.payeeModel, "toggleFavourite");
}
示例7: constructor
public constructor($qMockProvider: QMockProvider) {
const success: PromiseMockConfig<{scope: string}> = {
args: "good-script",
response: {scope: "test scope"}
},
error: PromiseMockConfig<string> = {
args: "bad-script",
response: "test error"
},
$q: QMock = $qMockProvider.$get();
// Mock $window object
this.$window = {
localStorage: {
getItem: sinon.stub(),
removeItem: sinon.stub(),
setItem: sinon.stub()
},
sessionStorage: {
getItem: sinon.stub(),
removeItem: sinon.stub(),
setItem: sinon.stub()
},
btoa: sinon.stub().returns("base64 encoded"),
navigator: {
serviceWorker: {
register: $q.promisify(success, error)
}
},
console: {
log: sinon.stub()
}
};
// Configure stub responses
this.$window.localStorage.getItem.withArgs("lootClosingBalance-1").returns(1000);
}
示例8: constructor
public constructor(securityMockProvider: SecurityMockProvider, securitiesMockProvider: SecuritiesMockProvider, $qMockProvider: QMockProvider) {
// Success/error = options for the stub promises
const success: PromiseMockConfig<{data: Security}> = {
args: {id: 1},
response: {data: securityMockProvider.$get()}
},
error: PromiseMockConfig<void> = {
args: {id: -1}
},
$q: QMock = $qMockProvider.$get();
// Mock securityModel object
this.securityModel = {
path(id: number): string {
return `/securities/${id}`;
},
recent: "recent securities list",
type: "security",
all: $q.promisify({
response: securitiesMockProvider.$get()
}),
allWithBalances: sinon.stub().returns(securitiesMockProvider.$get()),
find(id: number): SinonStub {
// Get the matching security
const security: Security = securitiesMockProvider.$get()[id - 1];
// Return a promise-like object that resolves with the security
return $q.promisify({response: security})();
},
findLastTransaction: $q.promisify({response: {}}, {args: -1}),
save: $q.promisify(success, error),
destroy: $q.promisify(success, error),
toggleFavourite(security: Security): SinonStub {
return $q.promisify({response: !security.favourite})();
},
flush: sinon.stub(),
addRecent: sinon.stub()
};
// Spy on find() and toggleFavourite()
sinon.spy(this.securityModel, "find");
sinon.spy(this.securityModel, "toggleFavourite");
}