I have a NextJS app using a MongoDB. I just added Jest for testing. When I run the first test I get the following error:
Please define the MONGODB_URI environment variable inside .env.local
4 |
5 | if (!MONGODB_URI) {
> 6 | throw new Error('Please define the MONGODB_URI environment variable inside .env.local');
| ^
7 | }
I do have a file .env.local
that has a MONGODB_URI and it works when I run my app locally and and on prod.
This is the test:
import React from 'react';
import ReactDom from 'react-dom';
import Home from '../../pages/index';
import { configure, shallow } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
configure({ adapter: new Adapter() });
describe('<Home />', () => {
it('should render Home', () => {
const wrapper = shallow(<Home />);
console.log('wrapper :', wrapper.debug());
});
});
My jest.config.js:
module.exports = {
clearMocks: true,
coverageDirectory: 'coverage',
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/fileMock.js',
'\\.(css|less)$': 'identity-obj-proxy'
},
preset: '@shelf/jest-mongodb'
};
What am I missing here?