index.test.ts 879 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { createApp, HooksApplication } from '@midwayjs/hooks-testing-library';
  2. import api, { post } from '.';
  3. describe('test new features', () => {
  4. let app: HooksApplication;
  5. beforeAll(async () => {
  6. app = await createApp();
  7. });
  8. afterAll(async () => {
  9. await app.close();
  10. });
  11. it('runFunction', async () => {
  12. expect(await app.runFunction(api)).toMatchInlineSnapshot(`
  13. Object {
  14. "message": "Hello World",
  15. "method": "GET",
  16. }
  17. `);
  18. expect(await app.runFunction(post, 'Jake')).toMatchInlineSnapshot(`
  19. Object {
  20. "method": "POST",
  21. "name": "Jake",
  22. }
  23. `);
  24. });
  25. it('request', async () => {
  26. const response = await app.request(api).expect(200);
  27. expect(response.body).toMatchInlineSnapshot(`
  28. Object {
  29. "message": "Hello World",
  30. "method": "GET",
  31. }
  32. `);
  33. });
  34. });