debian-mirror-gitlab/spec/frontend/__helpers__/assert_props.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1 KiB
JavaScript
Raw Normal View History

2023-06-20 00:43:36 +05:30
import { mount } from '@vue/test-utils';
import { ErrorWithStack } from 'jest-util';
2023-07-09 08:55:56 +05:30
function installConsoleHandler(method) {
const originalHandler = global.console[method];
global.console[method] = function throwableHandler(...args) {
if (args[0]?.includes('Invalid prop') || args[0]?.includes('Missing required prop')) {
throw new ErrorWithStack(
`Unexpected call of console.${method}() with:\n\n${args.join(', ')}`,
this[method],
);
}
originalHandler.apply(this, args);
};
return function restore() {
global.console[method] = originalHandler;
2023-06-20 00:43:36 +05:30
};
2023-07-09 08:55:56 +05:30
}
export function assertProps(Component, props, extraMountArgs = {}) {
const [restoreError, restoreWarn] = [
installConsoleHandler('error'),
installConsoleHandler('warn'),
];
2023-06-20 00:43:36 +05:30
const ComponentWithoutRenderFn = {
...Component,
render() {
return '';
},
};
try {
mount(ComponentWithoutRenderFn, { propsData: props, ...extraMountArgs });
} finally {
2023-07-09 08:55:56 +05:30
restoreError();
restoreWarn();
2023-06-20 00:43:36 +05:30
}
}