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


TypeScript egg-mock.app函数代码示例

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


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

示例1: describe

describe('test/app/controller/news.test.ts', () => {
  const app = mm.app();
  before(async () => {
    await app.ready();
  });

  after(() => app.close());

  afterEach(mm.restore);

  it('should GET /news', async () => {
    const result = await app.httpRequest().get('/news').expect(200);
    const $ = cheerio.load(result.text);
    const listItem = $('.news-view .item');
    assert(listItem.length === app.config.news.pageSize);
  });

  it('should GET /news/item/:id', async () => {
    await app.httpRequest()
    .get('/news/item/1')
    // just a example, use regex to test part of dom string, but should be strong characteristic
    .expect(/\/news\/item\/1/)
    .expect(200);
  });

  it('should GET /news/user/:id', async () => {
    await app.httpRequest()
    .get('/news/user/activatedgeek')
    // just a example, use regex to test part of dom string, but should be strong characteristic
    .expect(/<span class="label">user:<\/span> activatedgeek/)
    .expect(200);
  });
});
开发者ID:Jarvislike,项目名称:examples,代码行数:33,代码来源:news.test.ts

示例2: describe

describe('test/app/service/HackerNews.test.js', () => {
  const app = mm.app();
  let ctx: Context;

  before(async () => {
    await app.ready();
    ctx = app.mockContext();
  });

  after(() => app.close());
  afterEach(mm.restore);

  it('getTopStories', async () => {
    const list = await ctx.service.hackerNews.getTopStories();
    assert(list.length === 30);
  });

  it('getItem', async () => {
    const item = await ctx.service.hackerNews.getItem(1);
    assert(item.id && item.title && item.url);
  });
});
开发者ID:Jarvislike,项目名称:examples,代码行数:22,代码来源:HackerNews.test.ts

示例3:

import * as mm from 'egg-mock';

const app = mm.app();
app.ready();
app.mockService('foo', 'bar', ['123']);
const ctx = app.mockContext();
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:6,代码来源:egg-mock-tests.ts

示例4: before

 before(() => {
   app = mock.app({ typescript: true } as MockOption);
   return app.ready();
 });
开发者ID:eggjs,项目名称:egg-bin,代码行数:4,代码来源:index.test.ts


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