Veexyy
Veexyy

Reputation: 55

test tinymce in vue-test-utils but got "Cannot read property 'init' of undefined" error

I'm new in vue-test-utils and want to write test.spec.js for my Tinymce/index component, but when i run npm test i got this error:

● Tinymce › encountered a declaration exception

TypeError: Cannot read property 'init' of undefined

  122 |     initTinymce() {
  123 |       const _this = this
> 124 |       window.tinymce.init({
      | ^
  125 |         selector: `#${this.tinymceId}`,
  126 |         height: 430,
  127 |         min_height: 430,

And here is my test.spec.js

import Tinymce from '@/components/Tinymce/index'
import { mount, createLocalVue, shallowMount  } from '@vue/test-utils'
import Element from 'element-ui'

const localVue = createLocalVue()
localVue.use(Element)

describe('Tinymce', () => {
  const wrapper = shallowMount(Tinymce, {
    localVue,
    attachToDocument: true
  })

  it('emit functions run correct by order', () => {
    expect(wrapper.emittedByOrder().map(e => e.name)).toEqual(['input', 'backImgAdd'])
  })
})

Did i miss some config?

Upvotes: 0

Views: 1148

Answers (1)

mava
mava

Reputation: 2854

Is the Tinymce component working correctly outside of the test?
How do you attach the tinymce object to the window object?
So maybe you can debug when the window.tinymce gets defined and the init() method is available.
If you could give us more info how Tinymce component looks like,
it would be helpfull to check if there is something wrong with the lifecycle etc.

Upvotes: 1

Related Questions