Closed
Description
Version
1.0.0-beta.24
Reproduction link
https://github.com/kb-coder/vue-test-utils-bug
Steps to reproduce
- Pull down repro.
- 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
Labels
No labels