Skip to content

Commit e2aabc6

Browse files
author
Walker Leite
committed
test(account): refactor test to jest
1 parent f230ad7 commit e2aabc6

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

template/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"babel-eslint": "^8.2.2",
4949
"babel-jest": "^23.0.1",
5050
"regenerator-runtime": "^0.11.1",
51+
"supertest": "^3.1.0",
5152
"babel-plugin-transform-runtime": "^6.23.0",
5253
"babel-preset-env": "^1.6.1",
5354
"babel-preset-stage-2": "^6.24.1",

template/test/server/account.spec.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
import app from '../../server/server';
1+
import request from 'supertest';
2+
import createLoopback from './utils/create-loopback';
23

34
describe('Account', () => {
4-
const Account = app.models.Account;
55
const email = '936ue5+4bnywbeje42pw@sharklasers.com';
6+
let server;
67
let testAccount;
8+
let Account;
79

8-
beforeEach(() => {
9-
const appStarted = new Promise(res => app.addListener('started', res));
10-
app.start();
11-
return appStarted.then(() => Account
12-
.create({email, password: 'IuhEW7HI#&HUH3'})
13-
.then((acc) => {
14-
testAccount = acc;
15-
}));
10+
beforeEach(async () => {
11+
server = await createLoopback();
12+
Account = server.models.Account;
13+
testAccount = await Account.create({
14+
email,
15+
password: 'IuhEW7HI#&HUH3'
16+
});
1617
});
1718

18-
afterEach(() => {
19-
Account.destroyById(testAccount.id);
20-
app.close();
21-
});
19+
afterEach(() => Account.destroyById(testAccount.id));
2220

2321
it('has been correctly declared', () => {
24-
expect(Account).toInherits(app.models.User);
22+
expect(Account).toInherits(server.models.User);
2523
});
2624

27-
it('should send reset email to test user', () => request(app)
25+
it('should send reset email to test user', () => request(server)
2826
.post('/api/Accounts/reset')
29-
.send({email})
30-
.then(res => expect(res).to.status(204))).slow(5000).timeout(30000);
27+
.send({ email })
28+
.expect(204),
29+
30000,
30+
);
3131
});

0 commit comments

Comments
 (0)