Silent Vue Warning on Jest
If you need to use shallowMount
but your app are using globally registered components, you might get annoyed by so many warning logs appear on your terminal when running the unit testings.
To turn off the warnings, put this code below on your test setup files defined in your jest configuration.
global.beforeEach(() => {
// surpress Vue warn
spyOnConsoleError = jest
.spyOn(global.console, "error")
.mockImplementation((message) => {
if (!String(message).includes("[Vue warn]: : Unknown custom element")) {
consoleError(message);
}
});
});
This will let jest to silence only the unknown custom element error.