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

Functional component test fails at findComponent #187

Closed
cyberalien opened this issue Aug 23, 2020 · 5 comments
Closed

Functional component test fails at findComponent #187

cyberalien opened this issue Aug 23, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@cyberalien
Copy link

Simple test with functional component:

import { h } from 'vue';
import { mount } from '@vue/test-utils';

function Test(props, context) {
	return h('div', {
		...props,
		innerHTML: 'This is a test',
	});
}

describe('Mounting component', () => {
	test('with wrapper', () => {
		const Wrapper = {
			components: { Test },
			template: `<Test />`,
		};

		const wrapper = mount(Wrapper, {});
		const item = wrapper.findComponent(Test);
		expect(item.exists()).toBe(true);
	});

	test('without wrapper', () => {
		const wrapper = mount(Test, {});
		const item = wrapper.findComponent(Test);
		expect(item.exists()).toBe(true);
		expect(item.html()).toStrictEqual('<div>This is a test</div>');
	});
});

Both tests fail at findComponent() that returns null.

vue: 3.0.0-rc.7
vue/test-utils: 2.0.0-beta.2, also tried with latest build from this repo

@afontcu
Copy link
Member

afontcu commented Aug 23, 2020

Related to #184?

@cyberalien
Copy link
Author

Checked that branch. First test passes, second test fails.

@lmiller1990
Copy link
Member

After merging this #188 I will investigate this a little. I learned a lot in #184.

I believe this was not working in VTU v1 either. I expect some limitations to by applied to a found functional component (currently we cannot detect emitted events from them, for example).

In the meantime, I will be adding some warnings to let people know this is a known issue, such as here: #185

@lmiller1990 lmiller1990 added the bug Something isn't working label Aug 25, 2020
@cyberalien
Copy link
Author

Thanks!

As for VTU v1, it is working with similar functional component for Vue 2.

@lmiller1990
Copy link
Member

Fixed in #238

This will be in the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants