當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。