tflori / vue-template-loader-jest

Missing link between vue-template-loader and jest
MIT License
2 stars 0 forks source link

wrapper.find() hasn't access to template #1

Open verget opened 5 years ago

verget commented 5 years ago

For testing purpose, I try to trigger an event on some html element inside my component for check if my vuex action triggered. In my .spec file I try this:

import Component from '../../../src/components/component'

localVue.use(Vuex)

describe('Component', () => {

  beforeEach(() => {
    actions = {
      actionClick: jest.fn()
    }
    store = new Vuex.Store({
      state: {},
      actions
     })
  })

  it('trigget "actionClick" by button click', () => {
    const wrapper = shallowMount(Component, { store, localVue })
    wrapper.find('button').trigger('click')
    expect(actions.actionClick).toHaveBeenCalled()
  })
})

Template is simple: <button @click="triggerClick">test</button>

But I have nothing except [vue-test-utils]: find did not return button, cannot call trigger() on empty Wrapper Did I miss something?

tflori commented 5 years ago

this library is just for testing separated templates of typescript components. Have you tried this with an inline template like it is described here?

Have you tried to get wrapper.html() to see if it loads the template? And does it work when you build the application.

The signature of the component would be great. Maybe there I can see what is wrong...