Skip to content

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

Closed
@kb-coder

Description

@kb-coder

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions