api.test.ts 545 B

1234567891011121314151617181920
  1. import { createApp, close, createHttpRequest } from '@midwayjs/mock';
  2. import { Framework } from '@midwayjs/koa';
  3. describe('test/controller/home.test.ts', () => {
  4. it('should POST /api/get_user', async () => {
  5. // create app
  6. const app = await createApp<Framework>();
  7. // make request
  8. const result = await createHttpRequest(app).get('/api/get_user').query({ uid: 123 });
  9. // use expect by jest
  10. expect(result.status).toBe(200);
  11. expect(result.body.message).toBe('OK');
  12. // close app
  13. await close(app);
  14. });
  15. });