-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathEnableExpressErrorHandler.spec.js
34 lines (32 loc) · 1.08 KB
/
EnableExpressErrorHandler.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const request = require('../lib/request');
describe('Enable express error handler', () => {
it('should call the default handler in case of error, like updating a non existing object', async done => {
spyOn(console, 'error');
const parseServer = await reconfigureServer(
Object.assign({}, defaultConfiguration, {
enableExpressErrorHandler: true,
})
);
parseServer.app.use(function (err, req, res, next) {
expect(err.message).toBe('Object not found.');
next(err);
});
try {
await request({
method: 'PUT',
url: defaultConfiguration.serverURL + '/classes/AnyClass/nonExistingId',
headers: {
'X-Parse-Application-Id': defaultConfiguration.appId,
'X-Parse-Master-Key': defaultConfiguration.masterKey,
'Content-Type': 'application/json',
},
body: { someField: 'blablabla' },
});
fail('Should throw error');
} catch (response) {
expect(response).toBeDefined();
expect(response.status).toEqual(500);
parseServer.server.close(done);
}
});
});