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: wrap extended child components #840

Merged
merged 14 commits into from
Aug 5, 2018

Conversation

eddyerburgh
Copy link
Member

@eddyerburgh eddyerburgh commented Jul 21, 2018

Fixes #819
Fixes #790

For localVue to work we set Vue._base to be the localVue instance, so that component constructors are created by extending the localVue constructor with component options.

This is not the case for child components already extended with Vue.extend. Because they are already Vue constructors, they aren't extended from the localVue constructor. To fix this, we need to extend each extended component manually.

Previously we only replaced root components, with this PR we will overwrite nested extended components.

CC @lmiller1990

`to ensure it has the correct instance properties. ` +
`This means it is not possible to find the component ` +
`with a component selector. To find the component, ` +
`you must stub it manually using the stubs mounting ` +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't find({ name: 'foo' }) still work in this case? If so maybe that should be added here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it would, I'll add it.

This PR also makes your suggestion of searching by string name a lot more attractive, as it would solve this problem entirely 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be nice 👍 Lately I (and my team) have decided on the following practice:

  1. when finshing HTML elements, using the querySelector API
  2. when finding components, use the find(Component) API.

which I think is the most intuitive for onboarding people new to Vue and TDD.

@eddyerburgh eddyerburgh merged commit 4faf5fb into vuejs:dev Aug 5, 2018
@eddyerburgh eddyerburgh deleted the fix-extended-emitted branch August 5, 2018 15:13
@@ -389,8 +389,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
AsyncComponent: () => import('~resources/components/component.vue')
}
}
const wrapper = shallowMount(TestComponent)
expect(wrapper.find({ name: 'AsyncComponent' }).exists()).to.equal(true)
Copy link

@chenxeed chenxeed May 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @eddyerburgh , sorry for commenting on such an old PR.

I was wondering why is the assertion for dynamic imports on shallowMount were removed? Seems like I cannot simply handles component as dynamic import with shallowMount anymore 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unit testing nested components - Child's emitted is undefined beforeCreate hook not called sometimes
3 participants