• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript types.StateMock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: describe

describe("CategoryIndexController", (): void => {
	let	categoryIndexController: CategoryIndexController,
			controllerTest: ControllerTestFactory,
			$transitions: angular.ui.IStateParamsService,
			$timeout: angular.ITimeoutService,
			$uibModal: UibModalMock,
			$state: StateMock,
			categoryModel: CategoryModelMock,
			ogTableNavigableService: OgTableNavigableService,
			categories: Category[],
			deregisterTransitionSuccessHook: SinonStub;

	// Load the modules
	beforeEach(angular.mock.module("lootMocks", "lootCategories", (mockDependenciesProvider: MockDependenciesProvider): void => mockDependenciesProvider.load(["$uibModal", "$state", "categoryModel", "categories"])));

	// Configure & compile the object under test
	beforeEach(inject((_controllerTest_: ControllerTestFactory, _$transitions_: angular.ui.IStateParamsService, _$timeout_: angular.ITimeoutService, _$uibModal_: UibModalMock, _$state_: StateMock, _categoryModel_: CategoryModelMock, _ogTableNavigableService_: OgTableNavigableService, _categories_: Category[]): void => {
		controllerTest = _controllerTest_;
		$transitions = _$transitions_;
		$timeout = _$timeout_;
		$uibModal = _$uibModal_;
		$state = _$state_;
		categoryModel = _categoryModel_;
		ogTableNavigableService = _ogTableNavigableService_;
		categories = _categories_;
		deregisterTransitionSuccessHook = sinon.stub();
		sinon.stub($transitions, "onSuccess").returns(deregisterTransitionSuccessHook);
		categoryIndexController = controllerTest("CategoryIndexController") as CategoryIndexController;
	}));

	it("should flatten the passed categories & subcategories and make them available to the view", (): void => {
		const firstParent: Category = angular.copy(categories[0]),
					[firstChild]: Category[] = firstParent.children as Category[];

		delete firstParent.children;
		categoryIndexController.categories[0].should.deep.equal(firstParent);
		categoryIndexController.categories[1].should.deep.equal(firstChild);
		categoryIndexController.categories.length.should.equal(15);
	});

	it("should focus the category when a category id is specified", (): void => {
		$state.params.id = "1";
		categoryIndexController = controllerTest("CategoryIndexController", {$state}) as CategoryIndexController;
		categoryIndexController.tableActions.focusRow = sinon.stub();
		$timeout.flush();
		(categoryIndexController.tableActions as OgTableActionHandlers).focusRow.should.have.been.calledWith(0);
	});

	it("should not focus the category when a category id is not specified", (): void =>	$timeout.verifyNoPendingTasks());

	it("should register a success transition hook", (): Chai.Assertion => $transitions.onSuccess.should.have.been.calledWith({to: "root.categories.category"}, sinon.match.func));

	it("should deregister the success transition hook when the scope is destroyed", (): void => {
		(categoryIndexController as angular.IController).$scope.$emit("$destroy");
		deregisterTransitionSuccessHook.should.have.been.called;
	});

	it("should ensure the category is focussed when the category id state param changes", (): void => {
		const toParams: {id: string} = {id: "1"};

		sinon.stub(categoryIndexController, "focusCategory" as keyof CategoryIndexController);
		$transitions.onSuccess.firstCall.args[1]({params: sinon.stub().withArgs("to").returns(toParams)});
		categoryIndexController["focusCategory"].should.have.been.calledWith(Number(toParams.id));
	});

	describe("editCategory", (): void => {
		let category: Category;

		// Helper function to resort the categories array by id
		function byId(a: Category, b: Category): number {
			return a.id < b.id ? -1 : 1;
		}

		beforeEach((): void => {
			sinon.stub(categoryIndexController, "focusCategory" as keyof CategoryIndexController);
			category = angular.copy(categoryIndexController.categories[1]);
		});

		it("should disable navigation on the table", (): void => {
			categoryIndexController.editCategory();
			ogTableNavigableService.enabled.should.be.false;
		});

		describe("(edit existing)", (): void => {
			beforeEach((): void => categoryIndexController.editCategory(1));

			it("should open the edit category modal with a category", (): void => {
				$uibModal.open.should.have.been.called;
				categoryModel.addRecent.should.have.been.calledWith(category);
				(($uibModal.resolves as UibModalMockResolves).category as Category).should.deep.equal(category);
			});

			it("should not change the parent's children count if the parent category has not changed", (): void => {
				$uibModal.close(category);
				categoryIndexController.categories[0].num_children.should.equal(2);
			});

			it("should decrement the original parent's children count when the parent category changes", (): void => {
				category.parent_id = 2;
				$uibModal.close(category);
//.........这里部分代码省略.........
开发者ID:scottohara,项目名称:loot,代码行数:101,代码来源:index.ts


示例2: describe

describe("ScheduleIndexController", (): void => {
	let	scheduleIndexController: ScheduleIndexController,
			controllerTest: ControllerTestFactory,
			$transitions: angular.ui.IStateParamsService,
			$uibModal: UibModalMock,
			$timeout: angular.ITimeoutService,
			$state: StateMock,
			transactionModel: TransactionModelMock,
			ogTableNavigableService: OgTableNavigableService,
			schedules: ScheduledTransaction[],
			deregisterTransitionSuccessHook: SinonStub;

	// Load the modules
	beforeEach(angular.mock.module("lootMocks", "lootSchedules", (mockDependenciesProvider: MockDependenciesProvider): void => mockDependenciesProvider.load(["$uibModal", "$state", "scheduleModel", "transactionModel", "schedules"])));

	// Configure & compile the object under test
	beforeEach(inject((_controllerTest_: ControllerTestFactory, _$transitions_: angular.ui.IStateParamsService, _$uibModal_: UibModalMock, _$timeout_: angular.ITimeoutService, _$state_: StateMock, _transactionModel_: TransactionModelMock, _ogTableNavigableService_: OgTableNavigableService, _schedules_: ScheduledTransaction[]): void => {
		controllerTest = _controllerTest_;
		$transitions = _$transitions_;
		$uibModal = _$uibModal_;
		$timeout = _$timeout_;
		$state = _$state_;
		transactionModel = _transactionModel_;
		ogTableNavigableService = _ogTableNavigableService_;
		schedules = _schedules_;
		deregisterTransitionSuccessHook = sinon.stub();
		sinon.stub($transitions, "onSuccess").returns(deregisterTransitionSuccessHook);
		scheduleIndexController = controllerTest("ScheduleIndexController") as ScheduleIndexController;
	}));

	it("should make the passed schedules available to the view", (): Chai.Assertion => scheduleIndexController.schedules.should.deep.equal(schedules));

	it("should make today's date available to the view", (): Chai.Assertion => scheduleIndexController.today.should.deep.equal(startOfDay(new Date())));

	it("should focus the schedule when a schedule id is specified", (): void => {
		$state.params.id = "1";
		scheduleIndexController = controllerTest("ScheduleIndexController", {$state}) as ScheduleIndexController;
		scheduleIndexController.tableActions.focusRow = sinon.stub();
		$timeout.flush();
		(scheduleIndexController.tableActions as OgTableActionHandlers).focusRow.should.have.been.calledWith(0);
	});

	it("should not focus the schedule when a schedule id is not specified", (): void =>	$timeout.verifyNoPendingTasks());

	it("should register a success transition hook", (): Chai.Assertion => $transitions.onSuccess.should.have.been.calledWith({to: "root.schedules.schedule"}, sinon.match.func));

	it("should deregister the success transition hook when the scope is destroyed", (): void => {
		(scheduleIndexController as angular.IController).$scope.$emit("$destroy");
		deregisterTransitionSuccessHook.should.have.been.called;
	});

	it("should ensure the schedule is focussed when the schedule id state param changes", (): void => {
		const toParams: {id: string} = {id: "1"};

		sinon.stub(scheduleIndexController, "focusSchedule" as keyof ScheduleIndexController);
		$transitions.onSuccess.firstCall.args[1]({params: sinon.stub().withArgs("to").returns(toParams)});
		scheduleIndexController["focusSchedule"].should.have.been.calledWith(Number(toParams.id));
	});

	describe("editSchedule", (): void => {
		let schedule: ScheduledTransaction;

		beforeEach((): void => {
			sinon.stub(scheduleIndexController, "focusSchedule" as keyof ScheduleIndexController);
			schedule = angular.copy(scheduleIndexController.schedules[1]);
		});

		it("should disable navigation on the table", (): void => {
			scheduleIndexController["editSchedule"]();
			ogTableNavigableService.enabled.should.be.false;
		});

		describe("(edit existing)", (): void => {
			it("should open the edit schedule modal with a schedule", (): void => {
				scheduleIndexController["editSchedule"](1);
				$uibModal.open.should.have.been.called;
				(($uibModal.resolves as UibModalMockResolves).schedule as ScheduledTransaction).should.deep.equal(schedule);
				transactionModel.findSubtransactions.should.not.have.been.called;
			});

			const scenarios: SplitTransactionType[] = ["Split", "LoanRepayment", "Payslip"];

			scenarios.forEach((scenario: SplitTransactionType): void => {
				it(`should prefetch the subtransactions for a ${scenario} transaction`, (): void => {
					scheduleIndexController.schedules[1].transaction_type = scenario;
					scheduleIndexController["editSchedule"](1);
					transactionModel.findSubtransactions.should.have.been.calledWith(schedule.id);
					(($uibModal.resolves as UibModalMockResolves).schedule as ScheduledTransaction).should.eventually.have.property("subtransactions");
				});
			});

			it("should update the schedule in the list of schedules when the modal is closed", (): void => {
				schedule.memo = "edited schedule";
				scheduleIndexController["editSchedule"](1);
				$uibModal.close({data: schedule});
				scheduleIndexController.schedules.should.include(schedule);
			});
		});

		describe("(add new)", (): void => {
//.........这里部分代码省略.........
开发者ID:scottohara,项目名称:loot,代码行数:101,代码来源:index.ts


示例3: describe

describe("SecurityIndexController", (): void => {
	let	securityIndexController: SecurityIndexController,
			controllerTest: ControllerTestFactory,
			$transitions: angular.ui.IStateParamsService,
			$timeout: angular.ITimeoutService,
			$uibModal: UibModalMock,
			$state: StateMock,
			securityModel: SecurityModelMock,
			ogTableNavigableService: OgTableNavigableService,
			securities: Security[],
			deregisterTransitionSuccessHook: SinonStub;

	// Load the modules
	beforeEach(angular.mock.module("lootMocks", "lootSecurities", (mockDependenciesProvider: MockDependenciesProvider): void => mockDependenciesProvider.load(["$uibModal", "$state", "securityModel", "securities"])));

	// Configure & compile the object under test
	beforeEach(inject((_controllerTest_: ControllerTestFactory, _$transitions_: angular.ui.IStateParamsService, _$timeout_: angular.ITimeoutService, _$uibModal_: UibModalMock, _$state_: StateMock, _securityModel_: SecurityModelMock, _ogTableNavigableService_: OgTableNavigableService, _securities_: Security[]): void => {
		controllerTest = _controllerTest_;
		$transitions = _$transitions_;
		$timeout = _$timeout_;
		$uibModal = _$uibModal_;
		$state = _$state_;
		securityModel = _securityModel_;
		ogTableNavigableService = _ogTableNavigableService_;
		securities = _securities_;
		deregisterTransitionSuccessHook = sinon.stub();
		sinon.stub($transitions, "onSuccess").returns(deregisterTransitionSuccessHook);
		securityIndexController = controllerTest("SecurityIndexController") as SecurityIndexController;
	}));

	it("should make the passed securities available to the view", (): Chai.Assertion => securityIndexController.securities.should.deep.equal(securities));

	it("should return the sum of all security values, to 2 decimal places", (): Chai.Assertion => securityIndexController.totalValue.should.equal(45.01));

	it("should focus the security when a security id is specified", (): void => {
		$state.params.id = "1";
		securityIndexController = controllerTest("SecurityIndexController", {$state}) as SecurityIndexController;
		securityIndexController.tableActions.focusRow = sinon.stub();
		$timeout.flush();
		(securityIndexController.tableActions as OgTableActionHandlers).focusRow.should.have.been.calledWith(0);
	});

	it("should not focus the security when a security id is not specified", (): void =>	$timeout.verifyNoPendingTasks());

	it("should register a success transition hook", (): Chai.Assertion => $transitions.onSuccess.should.have.been.calledWith({to: "root.securities.security"}, sinon.match.func));

	it("should deregister the success transition hook when the scope is destroyed", (): void => {
		(securityIndexController as angular.IController).$scope.$emit("$destroy");
		deregisterTransitionSuccessHook.should.have.been.called;
	});

	it("should ensure the security is focussed when the security id state param changes", (): void => {
		const toParams: {id: string} = {id: "1"};

		sinon.stub(securityIndexController, "focusSecurity" as keyof SecurityIndexController);
		$transitions.onSuccess.firstCall.args[1]({params: sinon.stub().withArgs("to").returns(toParams)});
		securityIndexController["focusSecurity"].should.have.been.calledWith(Number(toParams.id));
	});

	describe("editSecurity", (): void => {
		let security: Security;

		beforeEach((): void => {
			sinon.stub(securityIndexController, "focusSecurity" as keyof SecurityIndexController);
			security = angular.copy(securityIndexController.securities[1]);
		});

		it("should disable navigation on the table", (): void => {
			securityIndexController.editSecurity();
			ogTableNavigableService.enabled.should.be.false;
		});

		describe("(edit existing)", (): void => {
			beforeEach((): void => securityIndexController.editSecurity(1));

			it("should open the edit security modal with a security", (): void => {
				$uibModal.open.should.have.been.called;
				securityModel.addRecent.should.have.been.calledWith(security);
				(($uibModal.resolves as UibModalMockResolves).security as Security).should.deep.equal(security);
			});

			it("should update the security in the list of securities when the modal is closed", (): void => {
				security.name = "edited security";
				$uibModal.close(security);
				securityIndexController.securities.should.include(security);
			});
		});

		describe("(add new)", (): void => {
			beforeEach((): void => {
				security = createSecurity({id: 999, unused: true});
				securityIndexController.editSecurity();
			});

			it("should open the edit security modal without a security", (): void => {
				$uibModal.open.should.have.been.called;
				securityModel.addRecent.should.not.have.been.called;
				(!($uibModal.resolves as UibModalMockResolves).security).should.be.true;
			});

//.........这里部分代码省略.........
开发者ID:scottohara,项目名称:loot,代码行数:101,代码来源:index.ts


示例4: describe

describe("PayeeIndexController", (): void => {
	let	payeeIndexController: PayeeIndexController,
			controllerTest: ControllerTestFactory,
			$transitions: angular.ui.IStateParamsService,
			$timeout: angular.ITimeoutService,
			$uibModal: UibModalMock,
			$state: StateMock,
			payeeModel: PayeeModelMock,
			ogTableNavigableService: OgTableNavigableService,
			payees: Payee[],
			deregisterTransitionSuccessHook: SinonStub;

	// Load the modules
	beforeEach(angular.mock.module("lootMocks", "lootPayees", (mockDependenciesProvider: MockDependenciesProvider): void => mockDependenciesProvider.load(["$uibModal", "$state", "payeeModel", "payees"])));

	// Configure & compile the object under test
	beforeEach(inject((_controllerTest_: ControllerTestFactory, _$transitions_: angular.ui.IStateParamsService, _$timeout_: angular.ITimeoutService, _$uibModal_: UibModalMock, _$state_: StateMock, _payeeModel_: PayeeModelMock, _ogTableNavigableService_: OgTableNavigableService, _payees_: Payee[]): void => {
		controllerTest = _controllerTest_;
		$transitions = _$transitions_;
		$timeout = _$timeout_;
		$uibModal = _$uibModal_;
		$state = _$state_;
		payeeModel = _payeeModel_;
		ogTableNavigableService = _ogTableNavigableService_;
		payees = _payees_;
		deregisterTransitionSuccessHook = sinon.stub();
		sinon.stub($transitions, "onSuccess").returns(deregisterTransitionSuccessHook);
		payeeIndexController = controllerTest("PayeeIndexController") as PayeeIndexController;
	}));

	it("should make the passed payees available to the view", (): Chai.Assertion => payeeIndexController.payees.should.deep.equal(payees));

	it("should focus the payee when a payee id is specified", (): void => {
		$state.params.id = "1";
		payeeIndexController = controllerTest("PayeeIndexController", {$state}) as PayeeIndexController;
		payeeIndexController.tableActions.focusRow = sinon.stub();
		$timeout.flush();
		(payeeIndexController.tableActions as OgTableActionHandlers).focusRow.should.have.been.calledWith(0);
	});

	it("should not focus the payee when a payee id is not specified", (): void =>	$timeout.verifyNoPendingTasks());

	it("should register a success transition hook", (): Chai.Assertion => $transitions.onSuccess.should.have.been.calledWith({to: "root.payees.payee"}, sinon.match.func));

	it("should deregister the success transition hook when the scope is destroyed", (): void => {
		(payeeIndexController as angular.IController).$scope.$emit("$destroy");
		deregisterTransitionSuccessHook.should.have.been.called;
	});

	it("should ensure the payee is focussed when the payee id state param changes", (): void => {
		const toParams: {id: string} = {id: "1"};

		sinon.stub(payeeIndexController, "focusPayee" as keyof PayeeIndexController);
		$transitions.onSuccess.firstCall.args[1]({params: sinon.stub().withArgs("to").returns(toParams)});
		payeeIndexController["focusPayee"].should.have.been.calledWith(Number(toParams.id));
	});

	describe("editPayee", (): void => {
		let payee: Payee;

		beforeEach((): void => {
			sinon.stub(payeeIndexController, "focusPayee" as keyof PayeeIndexController);
			payee = angular.copy(payeeIndexController.payees[1]);
		});

		it("should disable navigation on the table", (): void => {
			payeeIndexController.editPayee();
			ogTableNavigableService.enabled.should.be.false;
		});

		describe("(edit existing)", (): void => {
			beforeEach((): void => payeeIndexController.editPayee(1));

			it("should open the edit payee modal with a payee", (): void => {
				$uibModal.open.should.have.been.called;
				payeeModel.addRecent.should.have.been.calledWith(payee);
				(($uibModal.resolves as UibModalMockResolves).payee as Payee).should.deep.equal(payee);
			});

			it("should update the payee in the list of payees when the modal is closed", (): void => {
				payee.name = "edited payee";
				$uibModal.close(payee);
				payeeIndexController.payees.should.include(payee);
			});
		});

		describe("(add new)", (): void => {
			beforeEach((): void => {
				payee = createPayee({
					id: 999,
					name: "new payee"
				});
				payeeIndexController.editPayee();
			});

			it("should open the edit payee modal without a payee", (): void => {
				$uibModal.open.should.have.been.called;
				payeeModel.addRecent.should.not.have.been.called;
				(!($uibModal.resolves as UibModalMockResolves).payee).should.be.true;
			});
//.........这里部分代码省略.........
开发者ID:scottohara,项目名称:loot,代码行数:101,代码来源:index.ts


示例5:

		it("should focus a category when another category is currently focussed", (): void => {
			$state.currentState("**.category");
			categoryIndexController.tableActions.focusAction(3);
			$state.go.should.have.been.calledWith("^.category", {id: 2});
		});
开发者ID:scottohara,项目名称:loot,代码行数:5,代码来源:index.ts


示例6:

		it("should focus a schedule when another schedule is currently focussed", (): void => {
			$state.currentState("**.schedule");
			scheduleIndexController.tableActions.focusAction(1);
			$state.go.should.have.been.calledWith("^.schedule", {id: 2});
		});
开发者ID:scottohara,项目名称:loot,代码行数:5,代码来源:index.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript types.UibModalMock类代码示例发布时间:2022-05-25
下一篇:
TypeScript types.QMock类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap