Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would you test an express route with this app.ts structure ? #52

Open
m4nu56 opened this issue Dec 21, 2019 · 1 comment
Open

How would you test an express route with this app.ts structure ? #52

m4nu56 opened this issue Dec 21, 2019 · 1 comment
Labels
question Further information is requested

Comments

@m4nu56
Copy link

m4nu56 commented Dec 21, 2019

I've tried cutting the startServer() method with an expressApp() one that I can export:

export async function expressApp() {
  const app = express();
  await require('./loaders').default({ expressApp: app });
  return app;
}

async function startServer() {
  const app = await expressApp();
 ...
}

And in my test I try using it like I would normally do:

import request from 'supertest';
import { expressApp } from '../src/app';

describe('Analyze Movements', () => {
  test('succeeds list of analyze movements', async () => {
    const response = await request(expressApp)
      .get(`/analyze`)
      .expect(200);
    let body = response.body;
    expect(body.length).toBeGreaterThan(1);
  });
}

But I'm getting a SyntaxError: SyntaxError: Unexpected identifier queries.js:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import moment from 'moment';

I suspect this is a problem related with the fact that my expressApp() method is async but I can't figure it out..

@santiq santiq added the question Further information is requested label Feb 4, 2020
@jacquesikot
Copy link

jacquesikot commented Mar 6, 2021

use like this
carbon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants