• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript Sinon.match函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: it

        it('should generate a valid resource with a random 4-digit ID', () => {
            mockSerializer.toJSON.returns({$class: 'com.org'});
            mockSerializer.fromJSON.returns(mockResource);
            mockResource.validate = sandbox.stub();
            component['resourceDeclaration'] = mockClassDeclaration;

            // should start clean
            should.not.exist(component['definitionError']);

            // run method
            component['generateResource']();

            // should not result in definitionError
            should.not.exist(component['definitionError']);

            // resourceDefinition should be set as per serializer.toJSON output
            component['resourceDefinition'].should.equal('{\n  "$class": "com.org"\n}');

            // We use the following internal calls
            mockFactory.newResource.should.be.calledWith(undefined,
                                                        'class.declaration',
                                                        sinon.match(/[0-9]{4}/),
                                                        {
                                                        generate: 'empty',
                                                        includeOptionalFields: false,
                                                        disableValidation: true,
                                                        allowEmptyId: true
                                                        });
            component.onDefinitionChanged.should.be.calledOn;
        });
开发者ID:marlonprudente,项目名称:composer,代码行数:30,代码来源:resource.component.spec.ts


示例2: it

    it('does not redirect AJAX requests if token refresh fails with 400 error', async () => {
      const request = requestFixture({ headers: { 'kbn-xsrf': 'xsrf' }, path: '/some-path' });

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

      const authenticationError = new errors.BadRequest('failed to refresh token');
      callWithInternalUser
        .withArgs('shield.getAccessToken', {
          body: { grant_type: 'refresh_token', refresh_token: 'bar' },
        })
        .rejects(authenticationError);

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

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

      expect(request.headers).not.toHaveProperty('authorization');
      expect(authenticationResult.failed()).toBe(true);
      expect(authenticationResult.error).toBe(authenticationError);
      expect(authenticationResult.user).toBeUndefined();
      expect(authenticationResult.state).toBeUndefined();
    });
开发者ID:spalger,项目名称:kibana,代码行数:30,代码来源:token.test.ts


示例3: it

    it('fails for AJAX requests with user friendly message if refresh token is expired.', async () => {
      const request = requestFixture({ headers: { 'kbn-xsrf': 'xsrf' } });

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

      callWithInternalUser
        .withArgs('shield.getAccessToken', {
          body: { grant_type: 'refresh_token', refresh_token: 'expired-refresh-token' },
        })
        .rejects({ statusCode: 400 });

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

      expect(request.headers).not.toHaveProperty('authorization');
      expect(authenticationResult.failed()).toBe(true);
      expect(authenticationResult.error).toEqual(
        Boom.badRequest('Both elasticsearch access and refresh tokens are expired.')
      );
    });
开发者ID:,项目名称:,代码行数:27,代码来源:


示例4: it

  it("should return an expanded entity set, sending exactly one body", done => {
    const parser = new GetRequestParser();
    stub(parser, "parse")
      .withArgs({ relativeUrl: "/Posts?$expand=Children", body: "" })
      .returns({
        entitySetName: "Posts",
        type: GetRequestType.Collection,
        filterExpression: null,
        expandTree: { Children: {} },
      });

    const repository = new Repository<IFilterVisitor>();
    stub(repository, "getEntities")
      .withArgs(match(type => type.getName() === "Post"), { Children: {} }, null, match.any)
      .callsArgWith(3, Result.success([ { Id: "2" } ]));

    const responseSender = new GetResponseSenderStub();
    stub(responseSender, "arrayResult", entities => {
      assert.deepEqual(entities, [ { Id: "2" } ]);
      done();
    });

    const schema = new Schema();
    const getHandler = new GetHandler<IFilterVisitor>(schema, parser, repository, responseSender);

    getHandler.query({ relativeUrl: "/Posts?$expand=Children", body: "" }, null as any);
  });
开发者ID:disco-network,项目名称:odata-rdf-interface,代码行数:27,代码来源:queryengine_spec.ts


示例5: it

      it('redirects to `overwritten_session` if new SAML Response is for another realm.', async () => {
        const request = requestFixture({ payload: { SAMLResponse: 'saml-response-xml' } });
        const existingUser = { username: 'user', authentication_realm: { name: 'saml1' } };
        callWithRequest
          .withArgs(
            sinon.match({ headers: { authorization: 'Bearer existing-valid-token' } }),
            'shield.authenticate'
          )
          .resolves(existingUser);

        const newUser = { username: 'user', authentication_realm: { name: 'saml2' } };
        callWithRequest
          .withArgs(
            sinon.match({ headers: { authorization: 'Bearer new-valid-token' } }),
            'shield.authenticate'
          )
          .resolves(newUser);

        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/overwritten_session');
      });
开发者ID:spalger,项目名称:kibana,代码行数:46,代码来源:saml.test.ts


示例6: it

			it(`should push the ${report.description.toLowerCase()} report view`, (): void => {
				settingsController[`view${report.description}Report` as ReportHandler]();
				appController.pushView.should.have.been.calledWith("report", sinon.match({
					reportName: report.viewArgs.reportName,
					dataSource: sinon.match.func,
					args: report.viewArgs.args
				}));
			});
开发者ID:scottohara,项目名称:tvmanager,代码行数:8,代码来源:settings-controller_spec.ts


示例7: it

 it('add', function () {
   const s = new SpySubscriber();
   const set = new Set();
   sut = new SetObserver(LF.none, new Lifecycle(), set);
   sut.subscribe(s);
   set.add(1);
   expect(s.handleChange).to.have.been.calledWith('add', match(x => x[0] === 1));
 });
开发者ID:aurelia,项目名称:aurelia,代码行数:8,代码来源:set-observer.spec.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript Sinon.mock函数代码示例发布时间:2022-05-25
下一篇:
TypeScript Sinon.fake函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap