Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support passing functional components as stub implementation #700

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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