-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
40 lines (32 loc) · 1001 Bytes
/
index.test.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
35
36
37
38
39
40
//@flow
const gcfExpressApp = require('./index');
describe('gcf-express-app', () => {
test('request path without trailing slash', () => {
// req.path is url + query string i.e. /url?a=b&c=d
// req.url is only "url" i.e. /url
const req = { path: '', url: '' };
const res = {};
const app = jest.fn(req => {
expect(req.url[0]).toEqual('/');
});
// $FlowFixMe
const gcfApp = gcfExpressApp(app);
// $FlowFixMe
gcfApp(req, res);
expect(app).toHaveBeenCalledWith(req, res);
});
test('request path with trailing slash', () => {
// req.path is url + query string i.e. /url?a=b&c=d
// req.url is only "url" i.e. /url
const req = { path: '/testurl?a=b&c=d', url: '/testurl' };
const res = {};
const app = jest.fn(req => {
expect(req.url).toEqual('/testurl');
});
// $FlowFixMe
const gcfApp = gcfExpressApp(app);
// $FlowFixMe
gcfApp(req, res);
expect(app).toHaveBeenCalledWith(req, res);
});
});