I'm currently trying to test my Express apis with Supertest and Jest however I'm running into a problem that I can't seem to find the answer to.
This is my api.
router.get('/', async (req: Request, res: Response) => {
const products: ProductType[] = await MongooseModel.find({});
res.send(products);
});
This is my test suite.
import request from 'supertest';
import products from './products';
describe('GET /', () => {
it('responds with status 200', async () => {
const response = await request(products).get('/');
expect(response.statusCode).toBe(200);
});
});
And this is my babel.config.js
export const presets = [
['@babel/preset-env', { targets: { node: 'current' } }],
+'@babel/preset-typescript',
+'@babel/plugin-transform-modules-commonjs',
];
When I try to run the tests, I get this response:
.presets[1] must be a string, object, function
Could anyone please help me figure this headache out?
Thanks!
Remove the meaningless +
in your preset. +'@babel/preset-typescript'
is a number with its value NaN
, which is neither a string, an object nor a function. '@babel/preset-typescript'
(and the following one) may be what you want.