當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript assert.calledOnce方法代碼示例

本文整理匯總了TypeScript中Sinon.assert.calledOnce方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript assert.calledOnce方法的具體用法?TypeScript assert.calledOnce怎麽用?TypeScript assert.calledOnce使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Sinon.assert的用法示例。


在下文中一共展示了assert.calledOnce方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: test

    test('writes documents in bulk to the index', async () => {
      const index = '.myalias';
      const callCluster = sinon.stub();
      const docs = [
        {
          _id: 'niceguy:fredrogers',
          _source: {
            type: 'niceguy',
            niceguy: {
              aka: 'Mr Rogers',
            },
            quotes: ['The greatest gift you ever give is your honest self.'],
          },
        },
        {
          _id: 'badguy:rickygervais',
          _source: {
            type: 'badguy',
            badguy: {
              aka: 'Dominic Badguy',
            },
            migrationVersion: { badguy: '2.3.4' },
          },
        },
      ];

      callCluster.returns(
        Promise.resolve({
          items: [],
        })
      );

      await Index.write(callCluster, index, docs);

      sinon.assert.calledOnce(callCluster);
      expect(callCluster.args[0]).toMatchSnapshot();
    });
開發者ID:salihkardan,項目名稱:kibana,代碼行數:37,代碼來源:elastic_index.test.ts

示例2: it

    it('fails if new access token is rejected after successful refresh', async () => {
      const request = requestFixture();

      callWithRequest
        .withArgs(sinon.match({ headers: { authorization: 'Bearer foo' } }), 'shield.authenticate')
        .rejects({ statusCode: 401 });

      callWithInternalUser
        .withArgs('shield.getAccessToken', {
          body: { grant_type: 'refresh_token', refresh_token: 'bar' },
        })
        .resolves({ access_token: 'newfoo', refresh_token: 'newbar' });

      const authenticationError = new errors.AuthenticationException('Some error');
      callWithRequest
        .withArgs(
          sinon.match({ headers: { authorization: 'Bearer newfoo' } }),
          'shield.authenticate'
        )
        .rejects(authenticationError);

      const accessToken = 'foo';
      const refreshToken = 'bar';
      const authenticationResult = await provider.authenticate(request, {
        accessToken,
        refreshToken,
      });

      sinon.assert.calledTwice(callWithRequest);
      sinon.assert.calledOnce(callWithInternalUser);

      expect(request.headers).not.toHaveProperty('authorization');
      expect(authenticationResult.failed()).toBe(true);
      expect(authenticationResult.user).toBeUndefined();
      expect(authenticationResult.state).toBeUndefined();
      expect(authenticationResult.error).toEqual(authenticationError);
    });
開發者ID:spalger,項目名稱:kibana,代碼行數:37,代碼來源:token.test.ts

示例3: it

  it('should allow disposing the engine, stopping reusability', function(done) {
    const sandbox = sinon.createSandbox();
    const spy = sandbox.spy();

    type NiceSources = {
      other: Stream<string>;
    };
    type NiceSinks = {
      other: Stream<string>;
    };

    function app(sources: NiceSources): NiceSinks {
      return {
        other: sources.other.mapTo('a').debug(spy),
      };
    }

    let sinkCompleted = 0;
    function driver(sink: Stream<string>) {
      sink.addListener({
        complete: () => {
          sinkCompleted++;
        },
      });
      return xs.of('b');
    }

    const engine = setupReusable<NiceSources, NiceSinks>({other: driver});

    engine.run(app(engine.sources));
    sinon.assert.calledOnce(spy);
    sinon.assert.calledWithExactly(spy, 'a');
    sandbox.restore();
    engine.dispose();
    assert.strictEqual(sinkCompleted, 1);
    done();
  });
開發者ID:ntilwalli,項目名稱:cyclejs,代碼行數:37,代碼來源:setupReusable.ts

示例4: test

    test('fails if any document fails', async () => {
      const index = '.myalias';
      const callCluster = sinon.stub();
      const docs = [
        {
          _id: 'niceguy:fredrogers',
          _source: {
            type: 'niceguy',
            niceguy: {
              aka: 'Mr Rogers',
            },
          },
        },
      ];

      callCluster.returns(
        Promise.resolve({
          items: [{ index: { error: { type: 'shazm', reason: 'dern' } } }],
        })
      );

      await expect(Index.write(callCluster, index, docs)).rejects.toThrow(/dern/);
      sinon.assert.calledOnce(callCluster);
    });
開發者ID:liuyepiaoxiang,項目名稱:kibana,代碼行數:24,代碼來源:elastic_index.test.ts

示例5: test

    test('creates the task manager index', async () => {
      const callCluster = sinon.spy();
      const store = new TaskStore({
        callCluster,
        index: 'tasky',
        maxAttempts: 2,
        supportedTypes: ['a', 'b', 'c'],
      });

      await store.init();

      sinon.assert.calledOnce(callCluster);

      sinon.assert.calledWithMatch(callCluster, 'indices.putTemplate', {
        body: {
          index_patterns: ['tasky'],
          settings: {
            number_of_shards: 1,
            auto_expand_replicas: '0-1',
          },
        },
        name: 'tasky',
      });
    });
開發者ID:liuyepiaoxiang,項目名稱:kibana,代碼行數:24,代碼來源:task_store.test.ts

示例6: it

    it('clears session if it belongs to not configured provider.', async () => {
      // Add `kbn-xsrf` header to the raw part of the request to make `can_redirect_request`
      // think that it's AJAX request and redirect logic shouldn't be triggered.
      const systemAPIRequest = requestFixture({
        headers: { xCustomHeader: 'xxx', 'kbn-xsrf': 'xsrf' },
      });
      const notSystemAPIRequest = requestFixture({
        headers: { xCustomHeader: 'yyy', 'kbn-xsrf': 'xsrf' },
      });

      session.get.withArgs(systemAPIRequest).resolves({
        state: { accessToken: 'some old token' },
        provider: 'token',
      });

      session.get.withArgs(notSystemAPIRequest).resolves({
        state: { accessToken: 'some old token' },
        provider: 'token',
      });

      session.clear.resolves();

      server.plugins.kibana.systemApi.isSystemApiRequest
        .withArgs(systemAPIRequest)
        .returns(true)
        .withArgs(notSystemAPIRequest)
        .returns(false);

      const systemAPIAuthenticationResult = await authenticate(systemAPIRequest);
      expect(systemAPIAuthenticationResult.notHandled()).toBe(true);
      sinon.assert.calledOnce(session.clear);

      const notSystemAPIAuthenticationResult = await authenticate(notSystemAPIRequest);
      expect(notSystemAPIAuthenticationResult.notHandled()).toBe(true);
      sinon.assert.calledTwice(session.clear);
    });
開發者ID:,項目名稱:,代碼行數:36,代碼來源:

示例7: it

			it('calls connected when client connects', () => {
				assert.calledOnce(connected);
			});
開發者ID:Agamnentzar,項目名稱:ag-sockets,代碼行數:3,代碼來源:serverClient.spec.ts

示例8: setTimeout

 setTimeout(() => {
   sinon.assert.calledOnce(disposeSpy)
   sandbox.restore()
   done()
 })
開發者ID:TylorS,項目名稱:tempest,代碼行數:5,代碼來源:index.ts

示例9: setTimeout

            setTimeout(() => {
                sinon.assert.calledOnce(callback);
                sinon.assert.calledOnce(callback2);

                done();
            }, 1);
開發者ID:spatools,項目名稱:promizr,代碼行數:6,代碼來源:tasks.ts


注:本文中的Sinon.assert.calledOnce方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。