Skip to content

Without jsdom as default, the tests don't pass #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sebastianrothe opened this issue Sep 15, 2021 · 0 comments · Fixed by #31
Closed

Without jsdom as default, the tests don't pass #27

sebastianrothe opened this issue Sep 15, 2021 · 0 comments · Fixed by #31
Assignees
Labels
bug Something isn't working

Comments

@sebastianrothe
Copy link

If I don't choose jsdom as a default for jest, the generated tests don't pass. I get

❯❯❯❯ npm run test                                                                                     ~/D/w/s/f/s/e/sveltekit master

> [email protected] test
> NODE_OPTIONS=--experimental-vm-modules jest src --config jest.config.json

(node:87367) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
 FAIL  src/routes/index-dom.spec.ts
  Index
    once the component has been rendered
      ✕ should show the proper heading (2 ms)

  ● Index › once the component has been rendered › should show the proper heading

    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

      19 |
      20 |   beforeEach(() => {
    > 21 |     renderedComponent = render(Index);
         |                         ^
      22 |   });
      23 |
      24 |   describe('once the component has been rendered', () => {

      at render (node_modules/@testing-library/svelte/dist/pure.js:53:28)
      at Object.<anonymous> (src/routes/index-dom.spec.ts:21:25)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        3.917 s, estimated 5 s
Ran all test suites matching /src/i.

This is solved by moving the comment:

/**
 * @jest-environment jsdom
 */

to the very top of the files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants