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


TypeScript Sinon.fake类代码示例

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


在下文中一共展示了fake类的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();
});
开发者ID:elastic,项目名称:kibana,代码行数:34,代码来源:delete_worker.test.ts

示例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);
  });
开发者ID:elastic,项目名称:kibana,代码行数:35,代码来源:clone_worker.ts

示例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();
});
开发者ID:elastic,项目名称:kibana,代码行数:34,代码来源:index_worker.test.ts

示例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,
            },
          },
        ],
      },
    })
  );
};
开发者ID:elastic,项目名称:kibana,代码行数:25,代码来源:index_scheduler.test.ts

示例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,
        },
      }),
    })
  );
});
开发者ID:elastic,项目名称:kibana,代码行数:60,代码来源:repository_object_client.test.ts

示例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);
            });
        }
    });
开发者ID:dfinke,项目名称:vscode-powershell,代码行数:26,代码来源:main.test.ts

示例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,
  };
}
开发者ID:elastic,项目名称:kibana,代码行数:36,代码来源:lsp_indexer.ts


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