After trying multiple solutions from Stackoverflow related to mongoose errors, I am still facing a problem with the code below. I believe the issue lies elsewhere, but I am unable to pinpoint it.
This file is connected to other files as well.
.finally catch (it resolves part of the error)
const assert = require('assert');
const User = require('../src/users');
describe('Testing virtualType', () => {
it("Ensuring that the virtualType correctly returns the number of books owned by the user", (done) => {
const user1 = new User({
userName: 'Robin',
shopslist: [{ shopName: 'Lord of the Rings' }, { articleName: 'Grapes of Wrath' }]
});
user1.save()
.then(() => User.findOne({ userName: 'Robin' }))
.then((User) => {
assert(user1.countShops.length === 2);
})
.finally(done);
});
});
The terminal shows:
(node:19900) UnhandledPromiseRejectionWarning: ValidationError: user validation failed: shopslist.0.articleName: ArticleName is required, shopslist.1.shopName: ShopName is required
at new ValidationError
at process._tickCallback (internal/process/next_tick.js:61:11)
(node:19900) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 9)