Vue.js 在vue测试用例中测试tinymce,但得到;无法读取属性';初始';“未定义”的定义;错误
我是Vue.js 在vue测试用例中测试tinymce,但得到;无法读取属性';初始';“未定义”的定义;错误,vue.js,tinymce,vue-test-utils,Vue.js,Tinymce,Vue Test Utils,我是vue test utils新手,想为我的Tinymce/index组件编写test.spec.js,但当我运行npm test时,我遇到了以下错误: ● Tinymce›遇到声明异常 TypeError: Cannot read property 'init' of undefined 122 | initTinymce() { 123 | const _this = this > 124 | window.tinymce.init({
vue test utils
新手,想为我的Tinymce/index
组件编写test.spec.js
,但当我运行npm test
时,我遇到了以下错误:
● Tinymce›遇到声明异常
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,
这是我的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'])
})
})
我是否错过了一些
config
?在测试之外Tinymce
组件是否正常工作?如何将
tinymce
对象附加到窗口
对象?因此,当定义了
window.tinymce
并且init()
方法可用时,您可能可以进行调试。如果您能给我们提供更多关于
Tinymce
组件外观的信息,检查生命周期等是否有问题将是有益的