-
Notifications
You must be signed in to change notification settings - Fork 669
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
Can't find functional component #296
Comments
so as class component |
One work around is: const wrapper = mount(ParentComponent, {
stubs: {
functionalComponent: '<div class="functional" />'
}
})
expect(wrapper.findAll('.functional')).toHaveLength(1) |
For the sake of CSS / theming, most components should have specific class names or IDs anyway, depending on your code design. The best way to do this would be as above, using |
Thanks your opinions. It's not not elegant but acceptable. One last thing, should we add how to test functional component in doc? I can help that. |
We'll add support for One thing I'm wondering, since functional components don't create an instance, should we create a new Wrapper for them. This would include a |
Is there another way do to it? That seems like a lot to do just for functional components (I suppose that's a big just, they are kind of important). I am still learning about how |
@eddyerburgh As long as it's well documented on the disparity between the wrappers ( |
@eddyerburgh it's awesome to have Overall, don't worry about that. I think that people probably would not try to use |
This is fixed in beta.9 |
The following code does not work. functional.vue <script>
export default {
name: 'functional',
functional: true,
render: (createElement) => createElement('div', 'This is a functional component')
}
</script> parent.vue <template>
<div>
<functional />
</div>
</template>
<script>
import functional from './functional.vue'
export default {
name: 'parent',
components: {
functional
}
}
</script> import { mount } from '~vue-test-utils'
import Functional from '~resources/components/functional.vue'
import Parent from '~resources/components/parent.vue'
describe('mount', () => {
it('functional', () => {
const wrapper = mount(Parent)
const functional = wrapper.find(Functional)
expect(functional.text()).to.equal('This is a functional component')
})
}) Error: [vue-test-utils]: find did not return Component, cannot call text() on empty Wrapper |
@eddyerburgh this is still not working (since |
I notice that the example in #399 uses |
@dvic thanks for the info, I think the issue will be shallow |
This should be reopened |
@eddyerburgh reopen this please |
This issue is still here in v31 |
@Ruudieboy are you using the |
Yes im using My current workaround is to just add a class or id to the component and find it that way. |
Hi there,
I found that
find
can't get functional component.For instance:
I know that functional component is instanceless, so it's understandable that
wrapper
can't find it directly. However, that is really hard to test. One way is useref
to mark component but that is not ease-to-use when using multiple functional components in the same time.Any suggestions to test functional component? Otherwise, how do you think about supporting finding functional component?
The text was updated successfully, but these errors were encountered: