simulateMouse(type, x = 0, y = 0)
Simulates a mouse event of the element.
Arguments
type
(String
): The name of the event.
x
(Number
)[optional]: The x position of the mouse.
y
(Number
)[optional]: The y position of the mouse.
Returns
(Promise
): Returns a promise which resolves after the next update of the vue component lifecycle.
Example
import { mount, mountAsChild } from '@jasoeight/vue-testing';
import { expect } from 'chai';
import Example from './path/to/Example.vue';
describe('Example.vue', () => {
it('greets informal on mousemove the firstname(tested with mount())', done => {
const wrapper = mount(Example, {
propsData: {
firstname: 'John',
lastname: 'Doe'
}
});
let greetingValue = null;
wrapper.vm.$on('greet', value => {
greetingValue = value;
});
wrapper.find('li')[0].simulateMouse('mousemove')
.then(() => {
expect(greetingValue).to.equal('Hi John');
done();
})
.catch(result => {
done(result);
});
});
it('greets informal on mousemove the firstname(tested with mountAsChild())', done => {
const wrapper = mountAsChild(Example, {
props: {
firstname: 'John',
lastname: 'Doe'
}
});
let greetingValue = null;
wrapper.vm.$on('greet', value => {
greetingValue = value;
});
wrapper.find('li')[0].simulateMouse('mousemove')
.then(() => {
expect(greetingValue).to.equal('Hi John');
done();
})
.catch(result => {
done(result);
});
});
});