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

wrapper.attributes(attribute) does not return the same thing as wrapper.attributes().attribute #949

Closed
kb-coder opened this issue Aug 28, 2018 · 3 comments

Comments

@kb-coder
Copy link

Version

1.0.0-beta.24

Reproduction link

https://github.com/kb-coder/vue-test-utils-bug

Steps to reproduce

  1. Pull down repro.
  2. Run "npm run test:unit"

The two tests in HelloWorld.spec.js will fail.

What is expected?

Both tests should succeed. According to the docs (https://vue-test-utils.vuejs.org/api/wrapper/#attributes-key), I should be able to check the attribute using this syntax:

expect(element.attributes('for'), 'label for attribute').to.equal('myInput')

For example:

it('label for attribute should be "myInput"', mochaAsync(async () => {
    const msg = 'new message'
    const wrapper = await shallowMount(HelloWorld, {
      attachToDocument: true,
      propsData: { msg }
    })

    const element = wrapper.find('label')

    expect(element.attributes('for'), 'label for attribute').to.equal('myInput') // fails
  }))

What is actually happening?

The element.attributes('for') returns the entire element object and not the value of the 'for' attribute.

However, the following line does work:

expect(element.attributes().for, 'label for attribute').to.equal('myInput')

According to the documentation, both ways of getting to the attribute should work.


Console shows:

element.attributes('for')
{data-v-.....: "", for: "myInput" .....}
elements.attributes().for
"myInput"
@kb-coder
Copy link
Author

I tried this on both an input using the "type" attribute and a label using the "for" attribute. Both are included in the repro.

@38elements
Copy link
Contributor

attributes([key]) is added at #941.
It is 2 days ago.
This is not included in 1.0.0-beta.24.
https://github.com/vuejs/vue-test-utils/releases/tag/v1.0.0-beta.24

@eddyerburgh
Copy link
Member

The latest version is released now, so this feature will be working as intended

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

No branches or pull requests

3 participants