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


TypeScript assert.calledTwice方法代码示例

本文整理汇总了TypeScript中Sinon.assert.calledTwice方法的典型用法代码示例。如果您正苦于以下问题:TypeScript assert.calledTwice方法的具体用法?TypeScript assert.calledTwice怎么用?TypeScript assert.calledTwice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sinon.assert的用法示例。


在下文中一共展示了assert.calledTwice方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

    it('calls each registered getter once each call', async () => {
      const authScope = new AuthScopeService();
      const user = {} as any;
      const request = requestFixture();
      const getter1 = sinon.stub();
      const getter2 = sinon.stub();
      const getter3 = sinon.stub();

      authScope.registerGetter(getter1);
      authScope.registerGetter(getter2);
      authScope.registerGetter(getter3);

      await authScope.getForRequestAndUser(request, user);
      sinon.assert.calledOnce(getter1);
      sinon.assert.calledOnce(getter2);
      sinon.assert.calledOnce(getter3);

      await authScope.getForRequestAndUser(request, user);
      sinon.assert.calledTwice(getter1);
      sinon.assert.calledTwice(getter2);
      sinon.assert.calledTwice(getter3);

      await authScope.getForRequestAndUser(request, user);
      sinon.assert.calledThrice(getter1);
      sinon.assert.calledThrice(getter2);
      sinon.assert.calledThrice(getter3);
    });
开发者ID:elastic,项目名称:kibana,代码行数:27,代码来源:auth_scope_service.test.ts

示例2: it

    it('predicates are called with the same context and proper arguments', function () {
        const exampleContext = {some: 'context'},
            structure = {
                key0: sinon.stub().returns(true),
                key1: sinon.stub().returns(true)
            },
            exampleObject = {
                key0: 1,
                key1: 'string'
            };

        const extraArgs = [2, 3];
        const args = [exampleObject, ...extraArgs];
        isValidStructure.call(exampleContext, structure, ...args);
        isValidStructure(structure).call(exampleContext, ...args);

        sinon.assert.calledTwice(structure.key0);
        sinon.assert.calledTwice(structure.key1);

        sinon.assert.alwaysCalledOn(structure.key0, exampleContext);
        sinon.assert.alwaysCalledOn(structure.key1, exampleContext);

        sinon.assert.calledWith(structure.key0, 1, ...extraArgs);
        sinon.assert.calledWith(structure.key1, 'string', ...extraArgs);
    });
开发者ID:wookieb,项目名称:predicates,代码行数:25,代码来源:structureTest.ts

示例3: it

      it('fails if call to delete refresh token responds with an error', async () => {
        const request = requestFixture();
        const accessToken = 'foo';
        const refreshToken = 'bar';

        callWithInternalUser
          .withArgs('shield.deleteAccessToken', { body: { token: accessToken } })
          .returns({ invalidated_tokens: 1 });

        const failureReason = new Error('failed to delete token');
        callWithInternalUser
          .withArgs('shield.deleteAccessToken', { body: { refresh_token: refreshToken } })
          .rejects(failureReason);

        const authenticationResult = await provider.deauthenticate(request, {
          accessToken,
          refreshToken,
        });

        sinon.assert.calledTwice(callWithInternalUser);
        sinon.assert.calledWithExactly(callWithInternalUser, 'shield.deleteAccessToken', {
          body: { refresh_token: refreshToken },
        });

        expect(authenticationResult.failed()).toBe(true);
        expect(authenticationResult.error).toBe(failureReason);
      });
开发者ID:spalger,项目名称:kibana,代码行数:27,代码来源:token.test.ts

示例4: test

  test('waits for isMigrated, if there is an index conflict', async () => {
    const log = logStub();
    const pollInterval = 1;
    const runMigration = sinon.spy(() => {
      throw { body: { error: { index: '.foo', type: 'resource_already_exists_exception' } } };
    });
    const isMigrated = sinon.stub();

    isMigrated
      .onFirstCall()
      .returns(Promise.resolve(false))
      .onSecondCall()
      .returns(Promise.resolve(true));

    await coordinateMigration({
      log,
      runMigration,
      pollInterval,
      isMigrated,
    });

    sinon.assert.calledOnce(runMigration);
    sinon.assert.calledTwice(isMigrated);
    const warnings = log.warning.args.filter((msg: any) => /deleting index \.foo/.test(msg));
    expect(warnings.length).toEqual(1);
  });
开发者ID:gingerwizard,项目名称:kibana,代码行数:26,代码来源:migration_coordinator.test.ts

示例5: it

 it("should return false otherwise",sinon.test(function(){
     let isActiveStub = this.stub(utilities, "isActive", () => { return false });
     let result = utilities.checkExtensionType();
     sinon.assert.calledTwice(isActiveStub);
     expect(result).to.equal(false);
     expect(utilities.getExtensionType()).to.equal(Constants.ExtensionConstants.NO_EXTENSION);
 }));
开发者ID:Microsoft,项目名称:extension-manifest-editor,代码行数:7,代码来源:Utilities.test.ts

示例6: test

    test('creates the task manager index', async () => {
      const callCluster = sinon.stub();
      callCluster.withArgs('indices.getTemplate').returns(Promise.resolve({ tasky: {} }));
      const store = new TaskStore({
        callCluster,
        getKibanaUuid,
        logger: mockLogger(),
        index: 'tasky',
        maxAttempts: 2,
        supportedTypes: ['a', 'b', 'c'],
      });

      await store.init();

      sinon.assert.calledTwice(callCluster); // store.init calls twice: once to check for existing template, once to put the template (if needed)

      sinon.assert.calledWithMatch(callCluster, 'indices.putTemplate', {
        body: {
          index_patterns: ['tasky'],
          settings: {
            number_of_shards: 1,
            auto_expand_replicas: '0-1',
          },
        },
        name: 'tasky',
      });
    });
开发者ID:njd5475,项目名称:kibana,代码行数:27,代码来源:task_store.test.ts

示例7: it

      it('redirects to the home page if new SAML Response is for the same user.', async () => {
        const request = requestFixture({ payload: { SAMLResponse: 'saml-response-xml' } });
        const user = { username: 'user', authentication_realm: { name: 'saml1' } };
        callWithRequest.withArgs(request, 'shield.authenticate').resolves(user);

        callWithInternalUser
          .withArgs('shield.samlAuthenticate')
          .resolves({ access_token: 'new-valid-token', refresh_token: 'new-valid-refresh-token' });

        const deleteAccessTokenStub = callWithInternalUser
          .withArgs('shield.deleteAccessToken')
          .resolves({ invalidated_tokens: 1 });

        const authenticationResult = await provider.authenticate(request, {
          accessToken: 'existing-valid-token',
          refreshToken: 'existing-valid-refresh-token',
        });

        sinon.assert.calledWithExactly(callWithInternalUser, 'shield.samlAuthenticate', {
          body: { ids: [], content: 'saml-response-xml' },
        });

        sinon.assert.calledTwice(deleteAccessTokenStub);
        sinon.assert.calledWithExactly(deleteAccessTokenStub, 'shield.deleteAccessToken', {
          body: { token: 'existing-valid-token' },
        });
        sinon.assert.calledWithExactly(deleteAccessTokenStub, 'shield.deleteAccessToken', {
          body: { refresh_token: 'existing-valid-refresh-token' },
        });

        expect(authenticationResult.redirected()).toBe(true);
        expect(authenticationResult.redirectURL).toBe('/test-base-path/');
      });
开发者ID:spalger,项目名称:kibana,代码行数:33,代码来源:saml.test.ts

示例8: test

 test('callback is called when a toast is removed', () => {
   const { toastNotifications } = setup();
   const onChangeSpy = sinon.spy();
   toastNotifications.onChange(onChangeSpy);
   const toast = toastNotifications.add({});
   toastNotifications.remove(toast);
   sinon.assert.calledTwice(onChangeSpy);
 });
开发者ID:spalger,项目名称:kibana,代码行数:8,代码来源:toast_notifications.test.ts


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