Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/__helpers__/assert_props.js')
-rw-r--r--spec/frontend/__helpers__/assert_props.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/frontend/__helpers__/assert_props.js b/spec/frontend/__helpers__/assert_props.js
new file mode 100644
index 00000000000..9935719580a
--- /dev/null
+++ b/spec/frontend/__helpers__/assert_props.js
@@ -0,0 +1,41 @@
+import { mount } from '@vue/test-utils';
+import { ErrorWithStack } from 'jest-util';
+
+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;
+ };
+}
+
+export function assertProps(Component, props, extraMountArgs = {}) {
+ const [restoreError, restoreWarn] = [
+ installConsoleHandler('error'),
+ installConsoleHandler('warn'),
+ ];
+ const ComponentWithoutRenderFn = {
+ ...Component,
+ render() {
+ return '';
+ },
+ };
+
+ try {
+ mount(ComponentWithoutRenderFn, { propsData: props, ...extraMountArgs });
+ } finally {
+ restoreError();
+ restoreWarn();
+ }
+}