本文整理匯總了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);
});
});
示例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);
});
});
示例3:
import * as mm from 'egg-mock';
const app = mm.app();
app.ready();
app.mockService('foo', 'bar', ['123']);
const ctx = app.mockContext();
示例4: before
before(() => {
app = mock.app({ typescript: true } as MockOption);
return app.ready();
});