diff options
Diffstat (limited to 'spec/frontend/vue_compat_test_setup.js')
-rw-r--r-- | spec/frontend/vue_compat_test_setup.js | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/spec/frontend/vue_compat_test_setup.js b/spec/frontend/vue_compat_test_setup.js index 6eba9465c80..fe43f8f2617 100644 --- a/spec/frontend/vue_compat_test_setup.js +++ b/spec/frontend/vue_compat_test_setup.js @@ -76,9 +76,77 @@ if (global.document) { Vue.configureCompat(compatConfig); installVTUCompat(VTU, fullCompatConfig, compatH); + + jest.mock('vue', () => { + const actualVue = jest.requireActual('vue'); + actualVue.configureCompat(compatConfig); + return actualVue; + }); + + jest.mock('@vue/test-utils', () => { + const actualVTU = jest.requireActual('@vue/test-utils'); + + return { + ...actualVTU, + RouterLinkStub: { + ...actualVTU.RouterLinkStub, + render() { + const { default: defaultSlot } = this.$slots ?? {}; + const defaultSlotFn = + defaultSlot && typeof defaultSlot !== 'function' ? () => defaultSlot : defaultSlot; + return actualVTU.RouterLinkStub.render.call({ + $slots: defaultSlot ? { default: defaultSlotFn } : undefined, + custom: this.custom, + }); + }, + }, + }; + }); + + jest.mock('portal-vue', () => ({ + __esModule: true, + default: { + install: jest.fn(), + }, + Portal: {}, + PortalTarget: {}, + MountingPortal: { + template: '<h1>MOUNTING-PORTAL</h1>', + }, + Wormhole: {}, + })); + VTU.config.global.renderStubDefaultSlot = true; const noop = () => {}; + const invalidProperties = new Set(); + + const getDescriptor = (root, prop) => { + let obj = root; + while (obj != null) { + const desc = Object.getOwnPropertyDescriptor(obj, prop); + if (desc) { + return desc; + } + obj = Object.getPrototypeOf(obj); + } + return null; + }; + + const isPropertyValidOnDomNode = (prop) => { + if (invalidProperties.has(prop)) { + return false; + } + + const domNode = document.createElement('anonymous-stub'); + const descriptor = getDescriptor(domNode, prop); + if (descriptor && descriptor.get && !descriptor.set) { + invalidProperties.add(prop); + return false; + } + + return true; + }; VTU.config.plugins.createStubs = ({ name, component: rawComponent, registerStub }) => { const component = unwrapLegacyVueExtendComponent(rawComponent); @@ -126,7 +194,11 @@ if (global.document) { .filter(Boolean) : renderSlotByName('default'); - return Vue.h(`${hyphenatedName || 'anonymous'}-stub`, this.$props, slotContents); + const props = Object.fromEntries( + Object.entries(this.$props).filter(([prop]) => isPropertyValidOnDomNode(prop)), + ); + + return Vue.h(`${hyphenatedName || 'anonymous'}-stub`, props, slotContents); }, }); |