Skip to content

Getting a "ShadowRoot is not defined" error #293

Closed
@peripateticus

Description

@peripateticus

Hello!

So, we are in the process of upgrading Vue 2 -> 3 and, for unit tests, we use a combination of mochapack and @vue/test-utils for unit testing. Currently, I'm testing with @vue/test-utils@2.0.0-beta.14.

What is happening is that when I mount the component in the mocha spec file, I hit this error:

 WEBPACK  Compiling...
 WEBPACK  Compiled successfully in 1393ms
 MOCHA  Testing...

 RUNTIME EXCEPTION  Exception occurred while loading your tests
ReferenceError: ShadowRoot is not defined
    at normalizeContainer (/.../code/vunit-client/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.js:1261:30)
    at Object.app.mount (/.../code/vunit-client/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.js:1211:27)
    at mount (/.../code/vunit-client/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:2416:18)
    ...

Looking at the error stack at line 1261 in the @vue/runtime-dom/dist/runtime-dom.cjs.js code, it says that ShadowRoot is undefined. So, in the code, if I change that to a window.ShadowRoot, it's happy. I see that window.ShadowRoot exists when JSDOM is set up, prior to when the tests run.

Any ideas? Thanks for the help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions