Vue.js插件集成测试

时间:2019-03-19 03:39:49

标签: dom vue.js jestjs integration-testing

我有一个插件,我从一个现有项目中提取了一个vue创建的裸露项目,请参见下面的代码。插件在文档正文(src / plugin.js)中附加了一个div。它具有一个带有'test'文本的.vue组件,当单击Vue徽标(src / plugin.vue和vue-test-plugin.gif)时,该文本会更改可见性。

问题:

我能够通过src / main.js中的vm.$el.parentElement.getElementsByClassName('plugin-container')访问此插件的HTML元素,但是当我在测试文件(tests \ unit \ plugin.spec.js)中访问TypeError: Cannot read property 'getElementsByClassName' of null时,就会得到 PASS tests/unit/example.spec.js FAIL tests/unit/plugin.spec.js ● Plugin › should change visibility when Vue image is clicked TypeError: Cannot read property 'getElementsByClassName' of null 16 | 17 | const image = vm.$el.getElementsByTagName('img')[0]; > 18 | const pluginContainer = vm.$el.parentElement.getElementsByClassName('plugin-container').length; | ^ 19 | 20 | expect(pluginContainer).toBe(0); 21 | image.click(); at Object.getElementsByClassName (tests/unit/plugin.spec.js:18:50) Test Suites: 1 failed, 1 passed, 2 total Tests: 1 failed, 1 passed, 2 total Snapshots: 0 total Time: 2.266s Ran all test suites. Watch Usage: Press w to show more. )。

(snakes) C:\Users\Acer\pypy2.7-v7.0.0-win32>pypy
Python 2.7.13 (9112c8071614, Feb 06 2019, 23:10:08)
[PyPy 7.0.0 with MSC v.1500 32 bit] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>> pypy epto.py conf_epto 1
  File "<stdin>", line 1
    pypy epto.py conf_epto 1
         ^
SyntaxError: invalid syntax
>>>>

预期结果:

我希望我的考试能够顺利通过。

代码:

https://github.com/tomchoo46/vue-test-plugin中可用

0 个答案:

没有答案