test: middleware/error

This commit is contained in:
DIYgod
2019-01-29 19:15:06 +08:00
parent 8cec57eaec
commit d2fafd71db
2 changed files with 17 additions and 0 deletions
+3
View File
@@ -87,6 +87,9 @@ router.get('/', async (ctx) => {
});
router.get('/test/:id', (ctx) => {
if (ctx.params.id === '0') {
throw Error('Error test');
}
const item = [];
for (let i = 1; i < 6; i++) {
item.push({
+14
View File
@@ -0,0 +1,14 @@
const supertest = require('supertest');
const { server } = require('../../lib/index');
const request = supertest(server);
afterAll(() => {
server.close();
});
describe('error', () => {
it(`error`, async () => {
const response = await request.get('/test/0');
expect(response.text).toMatch(/RSSHub 发生了一些意外: <pre>Error: Error test/);
});
});