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


TypeScript supertest类代码示例

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


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

示例1: express

/// <reference path="supertest.d.ts" />
/// <reference path="../express/express.d.ts" />

import * as supertest from 'supertest';
import * as express from 'express';

const app = express();

supertest(app)
  .get('/user')
  .expect('Content-Type', /json/)
  .expect('Content-Length', '20')
  .expect(201)
  .end((err, res) => {
    if (err) throw err;
  });

// cookie scenario
const request = supertest(app);
const agent = supertest.agent();
request
  .post('/login')
  .end((err: any, res: supertest.Response) => {
    if (err) throw err;
    agent.saveCookies(res);

    const req = request.get('/admin');
    agent.attachCookies(req);
    req.expect(200, (err: any, res: supertest.Response) => {
      if (err) throw err;
    });
开发者ID:DavidKDeutsch,项目名称:DefinitelyTyped,代码行数:31,代码来源:supertest-tests.ts

示例2: express

import * as supertest from 'supertest';
import * as express from 'express';

const app = express();
const request: supertest.SuperTest<supertest.Test> = supertest(app);

(request
  .get('/user') as supertest.Test)
  .expect('Content-Type', /json/)
  .expect('Content-Length', '20')
  .expect(201)
  .end((err, res) => {
    if (err) throw err;
  });

// cookie scenario
const agent = supertest.agent();
request
  .post('/login')
  .end((err: any, res: supertest.Response) => {
    if (err) throw err;
    agent.saveCookies(res);

    const req = request.get('/admin') as supertest.Test;
    agent.attachCookies(req);
    req.expect(200, (err: any, res: supertest.Response) => {
      if (err) throw err;
    });
  });
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:29,代码来源:supertest-tests.ts

示例3: logger

function logger(format: String = '') {//最佳实践:中间件最好有名字(不用匿名函数)
    format = format || ':method | :url';

    return async function (ctx: Koa.Context, next: Function) {
        const str = format
            .replace(':method', ctx.method)
            .replace(':url', ctx.url);
        if (ctx.body) {
            ctx.body += ' ' + str;
        } else {
            ctx.body = str;
        }
        await next();
    };
}

app.use(logger(':method & :url'));

app.listen(3000);

supertest('http://localhost:3000')
    .get('/test')
    .expect(200)
    .expect('GET & /test')
    .end((err, res) => {
        if (err) {
            throw err;
        } else {
            console.log('测试通过!');
        }
    });
开发者ID:sagacite2,项目名称:test-koa-typescript,代码行数:31,代码来源:2.ts

示例4: request

 it('should render page when form is invalid and everything is fine', async () => {
   await request(app)
     .post(Paths.noClaimNumberPage.uri)
     .expect(res => expect(res).to.be.successful.withText('Which service did you use to view or make the claim?', 'div class="error-summary"'))
 })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:5,代码来源:no-claim-number.ts

示例5: it

  it("should return a delete", function(done) {

    request(app)
    .delete("/one/2")
    .expect('{"id":"2","method":"delete"}', done);
  });
开发者ID:lynchmaniac,项目名称:threerest,代码行数:6,代码来源:service-load.ts

示例6: request

 it(`/POST (Observable stream)`, () => {
   return request(server)
     .post('/?command=stream.sum')
     .send([1, 2, 3, 4, 5])
     .expect(200, '15');
 });
开发者ID:timokae,项目名称:nest,代码行数:6,代码来源:sum-nats.spec.ts

示例7: request

    it('should render page when everything is fine', async () => {

      await request(app)
        .get(pagePath)
        .expect(res => expect(res).to.be.successful.withText(expectedTextOnPage))
    })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:6,代码来源:claim-type.ts

示例8: request

 it('should render privacy policy page when everything is fine', async () => {
   await request(app)
     .get(Paths.privacyPolicyPage.uri)
     .expect(res => expect(res).to.be.successful.withText('Privacy policy'))
 })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:5,代码来源:privacy-policy.ts

示例9: request

 it('/ (GET)', () => {
   return request(app.getHttpServer())
     .get('/')
     .expect(200)
     .expect('Hello World!');
 });
开发者ID:2018-B-GR1-AplicacionesWeb,项目名称:Beltran-Venegas-Daniel-Alexander,代码行数:6,代码来源:app.e2e-spec.ts


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