当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript SinonStub.withArgs方法代码示例

本文整理汇总了TypeScript中Sinon.SinonStub.withArgs方法的典型用法代码示例。如果您正苦于以下问题:TypeScript SinonStub.withArgs方法的具体用法?TypeScript SinonStub.withArgs怎么用?TypeScript SinonStub.withArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sinon.SinonStub的用法示例。


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

示例1: test

    test('Adding a record to the memory source immediately pushes the update to the remote', async function(assert) {
      assert.expect(1);

      await coordinator.activate();

      let planet: Record = {
        type: 'planet',
        id: schema.generateId(),
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      };

      fetchStub.withArgs('/planets').returns(
        jsonapiResponse(201, {
          data: {
            id: planet.id,
            type: 'planets',
            attributes: { name: 'Jupiter', classification: 'gas giant' }
          }
        })
      );

      await memory.update(t => t.addRecord(planet));

      let result = memory.cache.query(q => q.findRecord(planet));

      assert.deepEqual(result, {
        type: 'planet',
        id: planet.id,
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      });
    });
开发者ID:orbitjs,项目名称:orbit.js,代码行数:31,代码来源:store-jsonapi-clientid-pessimistic-test.ts

示例2: 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

示例3: it

        it('should load documentation', async () => {
            // given
            fetchResource.withArgs('http://example.com/resource')
                .returns(mockedResponse({
                    xhrBuilder: responseBuilder().body(Bodies.someJsonLd),
                }));

            // when
            await Hydra.loadResource('http://example.com/resource');

            // then
            expect(fetchResource.calledWithMatch('http://api.example.com/doc/')).toBe(true);
        });
开发者ID:wikibus,项目名称:heracles,代码行数:13,代码来源:Heracles-spec.ts

示例4: xit

        xit('should return typed numeric literals as their values', async () => {
            // given
            fetchResource.withArgs('http://example.com/resource')
                .returns(mockedResponse({
                    xhrBuilder: responseBuilder().body(Bodies.typedNumericLiteral),
                }));

            // when
            const hydraRes = await Hydra.loadResource('http://example.com/resource');
            const res = hydraRes.get('http://example.com/resource');

            // then
            expect(res['http://schema.org/age']).toBe(21);
        });
开发者ID:wikibus,项目名称:heracles,代码行数:14,代码来源:Heracles-spec.ts


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