本文整理汇总了TypeScript中Sinon.fake.returns方法的典型用法代码示例。如果您正苦于以下问题:TypeScript fake.returns方法的具体用法?TypeScript fake.returns怎么用?TypeScript fake.returns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sinon.fake
的用法示例。
在下文中一共展示了fake.returns方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('On delete job completed.', async () => {
// Setup EsClient
const updateSpy = sinon.fake.returns(Promise.resolve());
const esClient = {
update: emptyAsyncFunc,
};
esClient.update = updateSpy;
const deleteWorker = new DeleteWorker(
esQueue as Esqueue,
log,
esClient as EsClient,
{} as ServerOptions,
{} as CancellationSerivce,
{} as LspService,
{} as RepositoryServiceFactory
);
await deleteWorker.onJobCompleted(
{
payload: {
uri: 'github.com/elastic/kibana',
},
options: {},
timestamp: 0,
},
{
uri: 'github.com/elastic/kibana',
}
);
// Nothing is called.
expect(updateSpy.notCalled).toBeTruthy();
});
示例2: it
it('Execute clone job', async () => {
// Setup RepositoryService
const cloneSpy = sinon.spy();
const repoService = {
clone: emptyAsyncFunc,
};
repoService.clone = cloneSpy;
const repoServiceFactory = {
newInstance: (): void => {
return;
},
};
const newInstanceSpy = sinon.fake.returns(repoService);
repoServiceFactory.newInstance = newInstanceSpy;
const cloneWorker = new CloneWorker(
esQueue as Esqueue,
log,
{} as EsClient,
serverOptions,
{} as IndexWorker,
(repoServiceFactory as any) as RepositoryServiceFactory
);
await cloneWorker.executeJob({
payload: {
url: 'https://github.com/Microsoft/TypeScript-Node-Starter.git',
},
options: {},
timestamp: 0,
});
assert.ok(newInstanceSpy.calledOnce);
assert.ok(cloneSpy.calledOnce);
});
示例3: test
test('On index job completed.', async () => {
// Setup EsClient
const updateSpy = sinon.fake.returns(Promise.resolve());
const esClient = {
update: emptyAsyncFunc,
};
esClient.update = updateSpy;
const indexWorker = new IndexWorker(
esQueue as Esqueue,
log,
esClient as EsClient,
[],
{} as ServerOptions,
{} as CancellationSerivce
);
await indexWorker.onJobCompleted(
{
payload: {
uri: 'github.com/elastic/kibana',
},
options: {},
timestamp: 0,
},
{
uri: 'github.com/elastic/kibana',
revision: 'master',
stats: new Map(),
}
);
expect(updateSpy.calledTwice).toBeTruthy();
});
示例4: moment
const createSearchSpy = (nextIndexTimestamp: number): sinon.SinonSpy => {
const repo: Repository = {
uri: 'github.com/elastic/code',
url: 'https://github.com/elastic/code.git',
org: 'elastic',
name: 'code',
revision: 'master',
nextIndexTimestamp: moment()
.add(nextIndexTimestamp, 'ms')
.toDate(),
};
return sinon.fake.returns(
Promise.resolve({
hits: {
hits: [
{
_source: {
[RepositoryReservedField]: repo,
},
},
],
},
})
);
};
示例5: test
test('CRUD of Repository', async () => {
const repoUri = 'github.com/elastic/code';
// Create
const indexSpy = sinon.spy(esClient, 'index');
const cObj: Repository = {
uri: repoUri,
url: 'https://github.com/elastic/code.git',
org: 'elastic',
name: 'code',
};
await repoObjectClient.setRepository(repoUri, cObj);
expect(indexSpy.calledOnce).toBeTruthy();
expect(indexSpy.getCall(0).args[0]).toEqual(
expect.objectContaining({
index: RepositoryIndexName(repoUri),
id: RepositoryReservedField,
body: JSON.stringify({
[RepositoryReservedField]: cObj,
}),
})
);
// Read
const getFake = sinon.fake.returns(
Promise.resolve({
_source: {
[RepositoryReservedField]: cObj,
},
})
);
esClient.get = getFake;
await repoObjectClient.getRepository(repoUri);
expect(getFake.calledOnce).toBeTruthy();
expect(getFake.getCall(0).args[0]).toEqual(
expect.objectContaining({
index: RepositoryIndexName(repoUri),
id: RepositoryReservedField,
})
);
// Update
const updateSpy = sinon.spy(esClient, 'update');
const uObj = {
url: 'https://github.com/elastic/codesearch.git',
};
await repoObjectClient.updateRepository(repoUri, uObj);
expect(updateSpy.calledOnce).toBeTruthy();
expect(updateSpy.getCall(0).args[0]).toEqual(
expect.objectContaining({
index: RepositoryIndexName(repoUri),
id: RepositoryReservedField,
body: JSON.stringify({
doc: {
[RepositoryReservedField]: uObj,
},
}),
})
);
});
示例6: suite
suite("Returns correct version of extension", () => {
const expectedVersion = "2.0.0";
const fake = sinon.fake.returns({ packageJSON: { version: expectedVersion, name: "PowerShell-Preview"} });
sinon.replace(vscode.extensions, "getExtension", fake);
const getCurrentVersion = RewiredMain.__get__("getCurrentVersion");
const testCases = [
{
description: "Testing supplying 'storagePath'",
data: { storagePath: "/my/path/to/ms-vscode.powershell-preview/foo" },
},
{
description: "Testing supplying 'extensionPath'",
data: { extensionPath: "/my/path/to/ms-vscode.powershell-preview/foo" },
},
{
description: "Testing supplying 'nothing'",
data: {},
},
];
for (const testCase of testCases) {
test(testCase.description, () => {
assert.equal(getCurrentVersion(testCase.data), expectedVersion);
});
}
});
示例7: setupEsClientSpy
function setupEsClientSpy() {
// Mock a git status of the repo indicating the the repo is fully cloned already.
const getSpy = sinon.fake.returns(
Promise.resolve({
_source: {
[RepositoryGitStatusReservedField]: {
uri: 'github.com/Microsoft/TypeScript-Node-Starter',
progress: WorkerReservedProgress.COMPLETED,
timestamp: new Date(),
cloneProgress: {
isCloned: true,
},
},
},
})
);
const existsAliasSpy = sinon.fake.returns(false);
const createSpy = sinon.spy();
const putAliasSpy = sinon.spy();
const deleteByQuerySpy = sinon.spy();
const bulkSpy = sinon.spy();
esClient.bulk = bulkSpy;
esClient.indices.existsAlias = existsAliasSpy;
esClient.indices.create = createSpy;
esClient.indices.putAlias = putAliasSpy;
esClient.get = getSpy;
esClient.deleteByQuery = deleteByQuerySpy;
return {
getSpy,
existsAliasSpy,
createSpy,
putAliasSpy,
deleteByQuerySpy,
bulkSpy,
};
}