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


TypeScript Sinon.assert類代碼示例

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


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

示例1: it

    it('relies SAML invalidate call even if access token is presented.', async () => {
      const request = requestFixture({ search: '?SAMLRequest=xxx%20yyy' });

      callWithInternalUser.withArgs('shield.samlInvalidate').resolves({ redirect: null });

      const authenticationResult = await provider.deauthenticate(request, {
        accessToken: 'x-saml-token',
        refreshToken: 'x-saml-refresh-token',
      });

      sinon.assert.calledOnce(callWithInternalUser);
      sinon.assert.calledWithExactly(callWithInternalUser, 'shield.samlInvalidate', {
        body: {
          queryString: 'SAMLRequest=xxx%20yyy',
          acs: 'test-protocol://test-hostname:1234/test-base-path/api/security/v1/saml',
        },
      });

      expect(authenticationResult.redirected()).toBe(true);
      expect(authenticationResult.redirectURL).toBe('/logged_out');
    });
開發者ID:njd5475,項目名稱:kibana,代碼行數:21,代碼來源:saml.test.ts

示例2:

                promizr.reduceRight(list, reduceTotal, iterator).then(result => {
                    sinon.assert.calledThrice(spy);

                    spy.getCall(0).args[0].should.equal(reduceTotal);
                    spy.getCall(0).args[1].should.equal(list[2]);

                    spy.getCall(1).args[0].should.equal(reduceTotal - list[2]);
                    spy.getCall(1).args[1].should.equal(list[1]);

                    spy.getCall(2).args[0].should.equal(reduceTotal - list[2] - list[1]);
                    spy.getCall(2).args[1].should.equal(list[0]);
                }).then(done, done);
開發者ID:spatools,項目名稱:promizr,代碼行數:12,代碼來源:collections.ts

示例3: it

    it('succeeds if only `authorization` header is available.', async () => {
      const request = BasicCredentials.decorateRequest(requestFixture(), 'user', 'password');
      const user = { username: 'user' };

      callWithRequest.withArgs(request, 'shield.authenticate').resolves(user);

      const authenticationResult = await provider.authenticate(request);

      expect(authenticationResult.succeeded()).toBe(true);
      expect(authenticationResult.user).toEqual(user);
      sinon.assert.calledOnce(callWithRequest);
    });
開發者ID:njd5475,項目名稱:kibana,代碼行數:12,代碼來源:basic.test.ts

示例4: 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

示例5: it

    it('clears session if provider failed to authenticate request with 401 with active session.', async () => {
      const systemAPIRequest = requestFixture({ headers: { xCustomHeader: 'xxx' } });
      const notSystemAPIRequest = requestFixture({ headers: { xCustomHeader: 'yyy' } });

      session.get.withArgs(systemAPIRequest).resolves({
        state: { authorization: 'Basic xxx' },
        provider: 'basic',
      });

      session.get.withArgs(notSystemAPIRequest).resolves({
        state: { authorization: 'Basic yyy' },
        provider: 'basic',
      });

      session.clear.resolves();

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

      cluster.callWithRequest
        .withArgs(systemAPIRequest)
        .rejects(Boom.unauthorized('token expired'))
        .withArgs(notSystemAPIRequest)
        .rejects(Boom.unauthorized('invalid token'));

      const systemAPIAuthenticationResult = await authenticate(systemAPIRequest);
      expect(systemAPIAuthenticationResult.failed()).toBe(true);

      sinon.assert.calledOnce(session.clear);
      sinon.assert.calledWithExactly(session.clear, systemAPIRequest);

      const notSystemAPIAuthenticationResult = await authenticate(notSystemAPIRequest);
      expect(notSystemAPIAuthenticationResult.failed()).toBe(true);

      sinon.assert.calledTwice(session.clear);
      sinon.assert.calledWithExactly(session.clear, notSystemAPIRequest);
    });
開發者ID:,項目名稱:,代碼行數:40,代碼來源:

示例6: it

  it('should not create unnecessary subscriptions with computeds', function() {
    const kObsA = ko.observable("a");
    const kObsB = ko.observable("b");
    const spyA = sinon.spy((a: any) => a);
    const spyB = sinon.spy((a: any) => a);
    const gObsA = computed((use) => spyA(use(kObsA)));
    const gObsB = pureComputed((use) => spyB(use(kObsB)));

    // A computed notices a change immediately.
    assertResetSingleCall(spyA, undefined, "a");
    assert.equal(gObsA.get(), "a");
    kObsA("A");
    assertResetSingleCall(spyA, undefined, "A");
    assert.equal(gObsA.get(), "A");
    sinon.assert.notCalled(spyA);

    // pureComputed notices a change only when looked at.
    sinon.assert.notCalled(spyB);
    assert.equal(gObsB.get(), "b");
    assertResetSingleCall(spyB, undefined, "b");
    kObsB("B");
    sinon.assert.notCalled(spyB);
    assert.equal(gObsB.get(), "B");
    assertResetSingleCall(spyB, undefined, "B");

    // This is the crux of the matter: kObsB does not have a subscription.
    assert.equal(kObsA.getSubscriptionsCount(), 1);
    assert.equal(kObsB.getSubscriptionsCount(), 0);     // pureComputed doesn't subscribe when inactive

    // Now subscribe to both gObs computeds.
    const spyA2 = sinon.spy((a: any) => a);
    const spyB2 = sinon.spy((a: any) => a);
    const lisA = gObsA.addListener(spyA2);
    const lisB = gObsB.addListener(spyB2);
    assertResetSingleCall(spyB, undefined, "B");

    // Now pureComputed acts as computed and subscribes too.
    assert.equal(kObsA.getSubscriptionsCount(), 1);
    assert.equal(kObsB.getSubscriptionsCount(), 1);

    kObsA("aa");
    assertResetSingleCall(spyA, undefined, "aa");
    assertResetSingleCall(spyA2, undefined, "aa", "A");
    kObsB("bb");
    assertResetSingleCall(spyB, undefined, "bb");
    assertResetSingleCall(spyB2, undefined, "bb", "B");

    // When we unsubscribe, count should go back to 0.
    lisA.dispose();
    lisB.dispose();
    assert.equal(kObsA.getSubscriptionsCount(), 1);
    assert.equal(kObsB.getSubscriptionsCount(), 0);

    kObsA("AA");
    assertResetSingleCall(spyA, undefined, "AA");
    sinon.assert.notCalled(spyA2);
    kObsB("bb");
    sinon.assert.notCalled(spyB);
    sinon.assert.notCalled(spyB2);
  });
開發者ID:gristlabs,項目名稱:grainjs,代碼行數:60,代碼來源:kowrap.ts

示例7: it

  it('should work with nulls', function() {
    let f: Foo|null;
    let g: Foo|null;
    const obs = observable("");
    const comp = computed(obs, (use, val) => val ? Foo.create(use.owner, val) : null);
    f = comp.get();
    assert.strictEqual(f, null);
    sinon.assert.notCalled(fooConstruct);
    sinon.assert.notCalled(fooDispose);

    obs.set("b");     // This should trigger a re-evaluation of comp.
    g = comp.get();
    assertResetSingleCall(fooConstruct, g, "b");
    sinon.assert.notCalled(fooDispose);

    obs.set("");    // Triggers another reevaluation.
    f = comp.get();
    assert.strictEqual(f, null);
    sinon.assert.notCalled(fooConstruct);
    assertResetSingleCall(fooDispose, g);
    assert.isTrue(g && g.isDisposed());

    comp.dispose();
    sinon.assert.notCalled(fooConstruct);
    sinon.assert.notCalled(fooDispose);
  });
開發者ID:gristlabs,項目名稱:grainjs,代碼行數:26,代碼來源:computedHolder.ts

示例8: test

  test('validates various props', () => {
    const validators = {
      a: sinon.stub(),
      b: sinon.stub(),
      c: sinon.stub(),
    };
    docValidator(validators)({ type: 'a', b: 'foo' });

    sinon.assert.notCalled(validators.c);

    expect(validators.a.args).toEqual([[{ type: 'a', b: 'foo' }]]);
    expect(validators.b.args).toEqual([[{ type: 'a', b: 'foo' }]]);
  });
開發者ID:gingerwizard,項目名稱:kibana,代碼行數:13,代碼來源:validation.test.ts


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