Hello, I tried running the Jest example from README, it works pretty fine but whenever I try running Model.create() or/and running Model.find({_id: 'some-id'}) I got the following error:
TypeError: Cannot read property 'Decimal128' of null
at Object.<anonymous> (node_modules/mongoose/lib/types/decimal128.js:13:44)
at Object.<anonymous> (node_modules/mongoose/lib/utils.js:7:17)
at Object.<anonymous> (node_modules/mongoose/lib/statemachine.js:8:15)
at Object.<anonymous> (node_modules/mongoose/lib/internal.js:7:22)
this happens only with finding by the _id attribute but inserting new docs always throw that error and here's the example Im using
import mongoose from 'mongoose';
import MongoMemoryServer from 'mongodb-memory-server';
// May require additional time for downloading MongoDB binaries
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
let mongoServer;
beforeAll(async () => {
mongoServer = new MongoMemoryServer();
const mongoUri = await mongoServer.getConnectionString();
await mongoose.connect(mongoUri, {useNewUrlParser:true}, (err) => {
if (err) console.error(err);
});
});
afterAll(() => {
mongoose.disconnect();
mongoServer.stop();
});
describe('...', () => {
it("...", async () => {
const User = mongoose.model('User', new mongoose.Schema({ name: String }));
const newUser = await User.create({ name: 're' });
expect(newUser).toHaveProperty('name', 're');
});
});
It's mongoose error (not in this package).
Didn't meet it in our projects, so have no idea how it can be fixed.
Maybe somebody else solve it?
Please share a solution.
@nodkz its a jest error I have solved it by removing "resetModules": true from my Jest config.
apologize for the misunderstanding I thought its something related to here, closing.
Most helpful comment
@nodkz its a jest error I have solved it by removing
"resetModules": truefrom my Jest config.