Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble adding unit test for trix events #178

Open
jessegavin opened this issue May 22, 2020 · 0 comments
Open

Trouble adding unit test for trix events #178

jessegavin opened this issue May 22, 2020 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@jessegavin
Copy link
Contributor

jessegavin commented May 22, 2020

Yesterday I submitted a PR #177 to add autofocus.

I tried to write a unit test for it and ran into some issues. I thought this test would do the job, however, the test always fails because the done() method never fires because the trix-initialize event is never triggered.

  it('autofocus focuses editor', async (done) => {
    const wrapper = mount(VueTrix, {
      propsData: {
        initContent: 'initContent',
        autofocus: true
      }
    })

    wrapper.vm.$on('trix-initialize', function (event) {
      expect(document.activeElement).toEqual(event.target)
      done()
    })
  })

I looked into this for a while. At first I thought it might be due to the fact that Trix uses customElements and JSDOM 15 (which is what Jest uses) doesn't support them. So I found a workaround where you can force jest to load JSDOM 16, but that didn't solve the issue. Turns out Trix ships with a polyfill for customElements anyways. So that was a bit of a dead end.

I am raising this issue because I was stumped by it and couldn't figure out how to make it work. I am curious if anyone else has any ideas.

@hanhdt hanhdt added the help wanted Extra attention is needed label May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants