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