Skip to content

Commit

Permalink
feat(Next): Add jest test without server running
Browse files Browse the repository at this point in the history
  • Loading branch information
danactive committed Apr 27, 2021
1 parent 4a52429 commit 905e454
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ coverage
tmp
.env
dist

public/resized
3 changes: 0 additions & 3 deletions api/server/plugins/gallery/test/.eslintrc.js

This file was deleted.

1 change: 1 addition & 0 deletions app/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14.16.0
18 changes: 12 additions & 6 deletions app/__tests__/api/galleryList/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
const fetch = require('node-fetch');
import { createMocks } from 'node-mocks-http';

import handleGalleryEndpoint from '../../../pages/api/galleryList';

describe('Gallery API', () => {
const utils = require('../../../../api/server/plugins/utils');
const port = utils.config.get('nextPort');

test('* Validate Gallery List route', async () => {
const endpoint = '/galleryList';
const url = `http://localhost:${port}/api${endpoint}`;
const { req, res } = createMocks({
method: 'GET',
query: {
animal: 'dog',
},
});

const response = await fetch(url);
expect(response.status).toBe(200);
await handleGalleryEndpoint(req, res);
expect(res._getStatusCode()).toBe(200);

const result = await response.json();
const result = JSON.parse(res._getData());
expect(result.galleries.includes('demo')).toBeTruthy();
});
});
85 changes: 85 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"identity-obj-proxy": "^3.0.0",
"jest": "^25.1.0",
"node-fetch": "^2.6.1",
"node-mocks-http": "^1.10.1",
"react-test-renderer": "^16.12.0"
},
"license": "MIT"
Expand Down

0 comments on commit 905e454

Please sign in to comment.