simulate(type, eventParameters = {})

Simulates a event of the element.

Arguments

type (String): The name of the event.

For key events also the key can be set (e.g. keyup.enter). Supported Keys:

  • enter: 13
  • tab: 9
  • delete: 46
  • esc: 27
  • space: 32
  • up: 38
  • down: 40
  • left: 37
  • right: 39

eventParameters (Object`)[optional]: Event options - see Event API

Returns

(Promise): Returns a promise which resolves after the next update of the vue component lifecycle.

Example

Example Component ExampleThree Component

import { mount, mountAsChild } from '@jasoeight/vue-testing';
import { expect } from 'chai';
import Example from './path/to/Example.vue';
import ExampleThree from './path/to/ExampleThree.vue';

describe('Example.vue', () => {
    it('greets formal when clicking on h1 element (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('h1')[0].simulate('click')
            .then(() => {
                expect(greetingValue).to.equal('Hello, John Doe');
                done();
            })
            .catch(result => {
                done(result);
            });
    });

    it('greets formal when clicking on h1 element (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('h1')[0].simulate('click')
            .then(() => {
                expect(greetingValue).to.equal('Hello, John Doe');
                done();
            })
            .catch(result => {
                done(result);
            });
    });

    it('ExampleThree.vue emits clicked-enter when (tested with mount())', done => {
        const wrapper = mount(ExampleThree);
        let clickedEnter = null;
        wrapper.vm.$on('clicked-enter', () => {
            clickedEnter = true;
        });

        wrapper.simulate('keyup.enter')
            .then(() => {
                expect(clickedEnter).to.be.true;
                done();
            })
            .catch(result => {
                done(result);
            });
    });

    it('ExampleThree.vue emits clicked-enter when (tested with mountAsChild())', done => {
        const wrapper = mountAsChild(ExampleThree);
        let clickedEnter = null;
        wrapper.vm.$on('clicked-enter', () => {
            clickedEnter = true;
        });

        wrapper.simulate('keyup.enter')
            .then(() => {
                expect(clickedEnter).to.be.true;
                done();
            })
            .catch(result => {
                done(result);
            });
    });
});

results matching ""

    No results matching ""