dimanche 6 septembre 2020

Testing plain javascript Vue components without Vue CLI

Is it possible to test Vue components that were developped in plain javascript without a Vue CLI/Webpack/Babel setup?

The documentation on the subjet I found so far on the Web is pretty slim :

I installed Vue, Vue test utils, JSDOM

My package.json :

{
  "name": "GuichetUnique.CMS",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "jest": "^26.4.2",
    "vue": "^2.6.12",
    "vue-template-compiler": "^2.6.12"
  },
  "devDependencies": {
    "@vue/test-utils": "^1.0.5",
    "jsdom": "16.4.0",
    "jsdom-global": "3.0.2"
  },
  "scripts": {
    "test": "jest"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Jest is running fine with simple js functions but I haven't manage to test a Vue component.

The content of my test

require('jsdom-global')();
var testUtils = require('@vue/test-utils'), Vue = require('vue');

testUtils.mount({ template: '<div>test</div>' });

The test result

TypeError: Illegal invocation at removeEventListener (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:15)

enter image description here

Please help !

Aucun commentaire:

Enregistrer un commentaire