本文整理汇总了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();
});