I'm making some tests using mookingose but they always pass even when showing some errors on the console,
This is an example of one of the tests
import mockingoose from 'mockingoose';
import { getUserById, insertUser } from '../controller/user';
import User from '../models/users';
import fetch from '../__mocks__/fetchnode';
describe('Test the user mongoose model', () => {
beforeEach(() => {
mockingoose.resetAll();
jest.clearAllMocks();
});
it('should return a valid user with findById user', () => {
mockingoose(User).toReturn(expectDoc, 'find');
getUserById('507f191e810c19729de860ea').then(res => {
expect(res.nickName).toBe(expectDoc.nickName);
});
});
it('should return the user doc with Save user', () => {
mockingoose(User).toReturn(expectDoc, 'save');
insertUser(expectDoc).then(res => {
expect(res.nickName).toBe(expectDoc.nickName);
});
});
it('should return error message with invalid user doc to save user', () => {
const OnlyAvatar = { avatar: expectDoc.avatar };
mockingoose(User).toReturn(OnlyAvatar, 'save');
insertUser(OnlyAvatar).catch(res => {
expect(res.message).toBe(
'AAAusers validation failed: name: Path `name` is required., nickName: Path `nickName` is required., email: Path `email` is required., password: Path `password` is required.',
);
});
});
});
Right now I'm having errors like these on the console:
Expected: "AAAusers validation failed: name: Path `name` is required., nickName: Path `nickName` is required., email: Path `email` is required., password: Path `password` i
s required."
Received: "users validation failed: name: Path `name` is required., nickName: Path `nickName` is required., email: Path `email` is required., password: Path `password` is
required."
(node:30984) 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: 2)
PASS src/routes/user.test.js
Test Suites: 5 passed, 5 total
Tests: 23 passed, 23 total
Snapshots: 0 total
Time: 3.057s
Ran all test suites matching /src\/routes\/category.test.js|src\/routes\/project.test.js|src\/routes\/task.test.js|src\/routes\/taskSearch.test.js|src\/routes\/user.test.
js/i.
The test should fail, but passes