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


TypeScript types.QMock類代碼示例

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


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

示例1: 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
		};
	}
開發者ID:scottohara,項目名稱:loot,代碼行數:10,代碼來源:authentication.ts

示例2: 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())
		};
	}
開發者ID:scottohara,項目名稱:loot,代碼行數:47,代碼來源:transaction.ts

示例3: 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");
	}
開發者ID:scottohara,項目名稱:loot,代碼行數:56,代碼來源:account.ts

示例4: 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)
		};
	}
開發者ID:scottohara,項目名稱:loot,代碼行數:18,代碼來源:schedule.ts

示例5: 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);
	}
開發者ID:scottohara,項目名稱:loot,代碼行數:37,代碼來源:window.ts

示例6: 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");
	}
開發者ID:scottohara,項目名稱:loot,代碼行數:51,代碼來源:category.ts

示例7: 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");
	}
開發者ID:scottohara,項目名稱:loot,代碼行數:41,代碼來源:payee.ts

示例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");
	}
開發者ID:scottohara,項目名稱:loot,代碼行數:43,代碼來源:security.ts


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