DEV Community

Discussion on: Creating a project template using Laravel, Vue 3, and Tailwind - Part 2

Collapse
 
anduru profile image
Andrey

how to solve the problem?

/var/www/html# npm run test

> test
> jest

 FAIL  tests/components/Home.test.js
   displays message (2 ms)

   displays message

    The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/configuration#testenvironment-string.
    Consider using the "jsdom" test environment.

    ReferenceError: document is not defined

       7 |
       8 | test("displays message", () => {
    >  9 |     const wrapper = mount(Home);
         |                     ^
      10 |
      11 |     expect(wrapper.text()).toContain("Home component");
      12 | });

      at mount (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:7840:14)
      at Object.<anonymous> (tests/components/Home.test.js:9:21)

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

Enter fullscreen mode Exit fullscreen mode
Collapse
 
kakeru007 profile image
kakeru007

So on your package.json, replace:
{
...
"scripts": {
...
"test": "jest"
...
},
}

with

{
...
"scripts": {
...
"test": "jest --env=jsdom"
...
},
}