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

Attr inheritance and InheritAttrs/InheritListeners #146

Closed
Austio opened this issue Nov 3, 2017 · 9 comments
Closed

Attr inheritance and InheritAttrs/InheritListeners #146

Austio opened this issue Nov 3, 2017 · 9 comments

Comments

@Austio
Copy link
Contributor

Austio commented Nov 3, 2017

👋 Edd

I was writing some specs on a component that uses the inheritAttrs option. While looking at that I noticed that none of the extra props I was passing to components were not being added as attributes on the component.

I dug a little deeper in the source and it appears the issue is that this occurs before the $mount function.

Please let me know what you think, have an example and some links below. Thanks!

// Example

<template>
  <button
    @click.prevent='handleClick'
  >
    <slot></slot>
  </button>
</template>

// Usage
<button-component :foo="bar">My Text</button-component>

// Vue would render
<button foo="bar">My Text</button>

// With `mount` from vue-test-utils
<button>My Text</button>

Reference in Vue.js https://vuejs.org/v2/guide/components.html#Non-Prop-Attributes

I saw this on avoriaz eddyerburgh/avoriaz#87

@Austio Austio changed the title InheritAttrs/InheritListeners Attr inheritance and InheritAttrs/InheritListeners Nov 3, 2017
@eddyerburgh
Copy link
Member

Hi Austio 😄

We should fix this. Are you able to make a PR?

@Austio
Copy link
Contributor Author

Austio commented Nov 3, 2017

@eddyerburgh yes should be able to knock out over the weekend.

@Austio
Copy link
Contributor Author

Austio commented Nov 6, 2017

Hey didn't make to over the weekend is a little more involved than was initially thinking, will work on this week.

@eddyerburgh
Copy link
Member

Hey @Austio, are you still intending to make a PR?

@eddyerburgh eddyerburgh mentioned this issue Dec 9, 2017
13 tasks
@Austio
Copy link
Contributor Author

Austio commented Dec 9, 2017

Hey Edd, my bad, yes I do, should have some free time in the coming up week to add. If you have freetime please feel free to jump on it :)

@Austio
Copy link
Contributor Author

Austio commented Dec 17, 2017

@eddyerburgh Hey so i worked on this and noticed something while i was working on the mount spec for it that i wanted to double check on. The attrs match but the rendered html is not what I expected. Could you check the spec here and the failed expectation to see if i'm on base? The PR has the rendered karma output from running the specs.

Line that is failing
https://github.com/Austio/vue-test-utils/blob/503f51d391cbe70eaf659eed30e0a495c7064c36/test/unit/specs/mount.spec.js#L158

PR (to my fork of vue-test-utils)
Austio#1

@Austio
Copy link
Contributor Author

Austio commented Dec 20, 2017

@eddyerburgh hey hey, just bumping on this, no rush

@eddyerburgh
Copy link
Member

Hi Austio, sorry for the delay getting back to you.

This behavior is due to how we add attrs once the vm is created. I'm looking into it now to see if there's a workaround

@nemtsov
Copy link

nemtsov commented Feb 7, 2018

@Austio thank you for working on this and making this library awesome!

If you're waiting for this, here's one workaround:

  beforeEach(function() {
    const WrapperComponent = {
      components: { Button },
      props: ['foo'],
      template: '<Button ref="unit" :foo="foo" />',
    };
    this.mountUnit = (props) => {
      const wrapper = mount(WrapperComponent, props);
      wrapper.vm.$refs = wrapper.vm.$refs.unit.$refs;
      return wrapper;
    };
  });

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

No branches or pull requests

3 participants