Skip to content

Commit

Permalink
test: use bootstrap to start tests (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Jul 30, 2023
1 parent 598a191 commit f94710f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
12 changes: 12 additions & 0 deletions unittest-jest/__tests__/controller/home.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const { app } = require('egg-mock/bootstrap');

describe('__tests__/controller/home.test.js', () => {
it('should status 200 and get the body', () => {
return app.httpRequest()
.get('/')
.expect(200)
.expect('hello world');
});
});
18 changes: 1 addition & 17 deletions unittest-jest/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
'use strict';

const mock = require('egg-mock');
const { app } = require('egg-mock/bootstrap');

describe('__tests__/index.test.js', () => {
let app;
beforeAll(() => {
app = mock.app();
return app.ready();
});

afterEach(mock.restore);
afterAll(() => app.close());

it('should app exist', () => {
expect(app.test).toBe('123');
});

it('should status 200 and get the body', () => {
return app.httpRequest()
.get('/')
.expect(200)
.expect('hello world');
});
});

0 comments on commit f94710f

Please sign in to comment.