-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow mounting functional components (#118)
* fix: allow mounting functional components * Apply suggestions from code review Co-authored-by: Carlos Rodrigues <[email protected]> Co-authored-by: Carlos Rodrigues <[email protected]>
- Loading branch information
1 parent
3fa0a19
commit fe21a93
Showing
2 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { mount } from '../src' | ||
import { h } from 'vue' | ||
import Hello from './components/Hello.vue' | ||
|
||
describe('functionalComponents', () => { | ||
it('mounts a functional component', () => { | ||
const Foo = (props: { msg: string }) => | ||
h('div', { class: 'foo' }, props.msg) | ||
|
||
const wrapper = mount(Foo, { | ||
props: { | ||
msg: 'foo' | ||
} | ||
}) | ||
|
||
expect(wrapper.html()).toEqual('<div class="foo">foo</div>') | ||
}) | ||
|
||
it('renders the slots of a functional component', () => { | ||
const Foo = (props, { slots }) => h('div', { class: 'foo' }, slots) | ||
|
||
const wrapper = mount(Foo, { | ||
slots: { | ||
default: 'just text' | ||
} | ||
}) | ||
|
||
expect(wrapper.html()).toEqual('<div class="foo">just text</div>') | ||
}) | ||
|
||
it('asserts classes', () => { | ||
const Foo = (props, { slots }) => h('div', { class: 'foo' }, slots) | ||
|
||
const wrapper = mount(Foo, { | ||
attrs: { | ||
class: 'extra_classes' | ||
} | ||
}) | ||
|
||
expect(wrapper.classes()).toContain('extra_classes') | ||
expect(wrapper.classes()).toContain('foo') | ||
}) | ||
|
||
it('uses `find`', () => { | ||
const Foo = () => h('div', { class: 'foo' }, h(Hello)) | ||
const wrapper = mount(Foo) | ||
|
||
expect(wrapper.find('#root').exists()).toBe(true) | ||
}) | ||
|
||
it('uses `findComponent`', () => { | ||
const Foo = () => h('div', { class: 'foo' }, h(Hello)) | ||
const wrapper = mount(Foo) | ||
|
||
expect(wrapper.findComponent(Hello).exists()).toBe(true) | ||
}) | ||
}) |