From 21c01976feea23467591b74ce5297aef8070ee69 Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Mon, 28 Jun 2021 08:41:29 +0300 Subject: [PATCH] fix: support passing functional components as stub implementation (#700) --- src/stubs.ts | 2 +- ...bs.global.spec.ts => global.stubs.spec.ts} | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) rename tests/mountingOptions/{stubs.global.spec.ts => global.stubs.spec.ts} (97%) diff --git a/src/stubs.ts b/src/stubs.ts index 008f361b6..0e4a7b2f1 100644 --- a/src/stubs.ts +++ b/src/stubs.ts @@ -182,7 +182,7 @@ export function stubComponents( } // case 2: custom implementation - if (stub && typeof stub === 'object') { + if (stub && stub !== true) { // pass the props and children, for advanced stubbing return [stubs[name], props, children, patchFlag, dynamicProps] } diff --git a/tests/mountingOptions/stubs.global.spec.ts b/tests/mountingOptions/global.stubs.spec.ts similarity index 97% rename from tests/mountingOptions/stubs.global.spec.ts rename to tests/mountingOptions/global.stubs.spec.ts index 1edad3e31..501c8dea2 100644 --- a/tests/mountingOptions/stubs.global.spec.ts +++ b/tests/mountingOptions/global.stubs.spec.ts @@ -212,6 +212,32 @@ describe('mounting options: stubs', () => { expect(wrapper.html()).toBe('
foo stub
') }) + it('uses functional component as a custom stub', () => { + const FooStub = () => h('div', 'foo stub') + const Foo = { + name: 'Foo', + render() { + return h('div', 'real foo') + } + } + + const Comp = { + render() { + return h(Foo) + } + } + + const wrapper = mount(Comp, { + global: { + stubs: { + Foo: FooStub + } + } + }) + + expect(wrapper.html()).toBe('
foo stub
') + }) + it('uses an sfc as a custom stub', () => { const created = jest.fn() const HelloComp = {