本文整理汇总了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' }
});
});
示例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");
}
示例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);
});
示例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);
});