mardi 16 février 2021

ReferenceError: ShadowRoot is not defined Jest and Vue3

I'm setting up Vue3 and Unit Test with Jest.

I already had to fight to make it work, and I already tried a lot of different configurations.

This is my last "working" configuration, and with this I get this error:

ReferenceError: ShadowRoot is not defined

I have actually no more ideas.

My configuration:

jest.config.js

module.exports = {
    transform: {
        "^.+\\.vue$": "vue-jest",
        "^.+\\.js$": "babel-jest",
        '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)(\\?inline)?$': 'jest-transform-stub',
    },
    moduleFileExtensions: ['vue', 'js', 'json', 'node'],
    transformIgnorePatterns: [
        "node_modules/(?!@jamescoyle/vue-icon)"
    ],
    moduleNameMapper: {
        "@/(.*)$": "<rootDir>/src/$1"
    }
}

header.test.js

import { mount } from '@vue/test-utils'
import Header from "./Header.vue";

test('Header', () => {
    const wrapper = mount(Header)
    console.log(wrapper.html())
})

The complete error:

> vue-cli-service test:unit

 FAIL  src/views/components/layout/Header/Header.test.js
  ✕ Header (11ms)

  ● Header

    ReferenceError: ShadowRoot is not defined

      3 |
      4 | test('Header', () => {
    > 5 |     const wrapper = mount(Header)
        |                     ^
      6 |     
      7 |     console.log(wrapper.html())
      8 | })

      at normalizeContainer (node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.js:1260:30)
      at Object.app.mount (node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.js:1211:27)
      at mount (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:2288:18)
      at Object.<anonymous> (src/views/components/layout/Header/Header.test.js:5:21)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.664s
Ran all test suites.

Aucun commentaire:

Enregistrer un commentaire