Skip to content

Commit

Permalink
fix: support passing functional components as stub implementation (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
xanf authored Jun 28, 2021
1 parent 015c765 commit 21c0197
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,32 @@ describe('mounting options: stubs', () => {
expect(wrapper.html()).toBe('<div>foo stub</div>')
})

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('<div>foo stub</div>')
})

it('uses an sfc as a custom stub', () => {
const created = jest.fn()
const HelloComp = {
Expand Down

0 comments on commit 21c0197

Please sign in to comment.