setAttribute(attribute, value)
Sets an attribute with the value to the element.
Arguments
attribute
(String
): The name of the attribute.
value
(String
): The value of the attribute.
Example
import { mount, mountAsChild } from '@jasoeight/vue-testing';
import { expect } from 'chai';
import Example from './path/to/Example.vue';
describe('Example.vue', () => {
it('sets the attribute "class" with the value "fullname" to the fullname element (tested with mount())', () => {
const wrapper = mount(Example);
const fullnameElement = wrapper.find('h1')[0];
expect(fullnameElement.hasAttribute('class', 'fullname')).to.be.false;
fullnameElement.setAttribute('class', 'fullname');
expect(fullnameElement.hasAttribute('class', 'fullname')).to.be.true;
});
it('sets the attribute "class" with the value "fullname" to the fullname element (tested with mountAsChild())', () => {
const wrapper = mountAsChild(Example);
const fullnameElement = wrapper.find('h1')[0];
expect(fullnameElement.hasAttribute('class', 'fullname')).to.be.false;
fullnameElement.setAttribute('class', 'fullname');
expect(fullnameElement.hasAttribute('class', 'fullname')).to.be.true;
});
});