mirror of
https://github.com/docker/getting-started-app.git
synced 2024-12-23 07:31:08 -05:00
20 lines
559 B
JavaScript
20 lines
559 B
JavaScript
|
const db = require('../../src/persistence');
|
||
|
const getItems = require('../../src/routes/getItems');
|
||
|
const ITEMS = [{ id: 12345 }];
|
||
|
|
||
|
jest.mock('../../src/persistence', () => ({
|
||
|
getItems: jest.fn(),
|
||
|
}));
|
||
|
|
||
|
test('it gets items correctly', async () => {
|
||
|
const req = {};
|
||
|
const res = { send: jest.fn() };
|
||
|
db.getItems.mockReturnValue(Promise.resolve(ITEMS));
|
||
|
|
||
|
await getItems(req, res);
|
||
|
|
||
|
expect(db.getItems.mock.calls.length).toBe(1);
|
||
|
expect(res.send.mock.calls[0].length).toBe(1);
|
||
|
expect(res.send.mock.calls[0][0]).toEqual(ITEMS);
|
||
|
});
|