當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。