Skip to content
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

Deno support #669

Closed
kirillgroshkov opened this issue May 14, 2020 · 7 comments
Closed

Deno support #669

kirillgroshkov opened this issue May 14, 2020 · 7 comments

Comments

@kirillgroshkov
Copy link

Sorry, https://twitter.com/kentcdodds/status/1260716918526242816
:)

@kentcdodds
Copy link
Member

Booo! 😆

lol, but in all seriousness, I'd be curious to know what it takes to support Deno, but I don't think we need an issue open about this as it's not a priority until someone could reasonably make JSDOM (or similar) work in Deno, so I'm going to close this.

@YOU54F
Copy link

YOU54F commented Apr 8, 2021

Hey @kentcdodds ,

I've started messing about with deno & react, using aleph.js and wanted to look at using react-testing-library or a deno equivalent, and stumbled across this.

We can use JSDOM in deno, example here

https://github.com/YOU54F/deno-examples/blob/main/jsdom/jsdom.test.ts

Only started using deno yesterday, out of curiosity to build an express like provider, and react based consumer equiv and exploring the available testing tools.

@kigiri
Copy link

kigiri commented Sep 13, 2021

You could also check https://github.com/b-fuze/deno-dom in a similar style, a more deno native lib.
Since deno handle JSX out of the box now, it could be a pretty nice DX to test react code without having to install and config anything, just deno run and your tests run

@Industrial
Copy link

Industrial commented Oct 1, 2022

Hello.

Libraries like JSDOM are working in Deno.

I am trying to get testing-library to work and keep getting the error:

error: TypeError: For queries bound to document.body a global document has to be available... Learn more: https://testing-library.com/s/screen-global-error
    at Object.helpers.<computed> [as queryByText] (https://esm.sh/v92/@testing-library/[email protected]/deno/dom.development.js:2365:11)
    at file:///home/tom/Code/code9/deno/test-fresh/components/Container.test.tsx:32:17

I have tried deno-dom-wasm, deno_dom, and jsdom but when I do:

  globalThis.document = document;
  globalThis.window.document = document;

I keep getting that error.

I'm not sure how to patch it correctly, since Deno provides a globalThis.window environment and it is readonly.

When using

import 'npm:global-jsdom/register'

But that throws the error:

error: TypeError: Cannot assign to read only property 'window' of object '#<Window>'

The DOM libraries are working by themselves. They just can't be put on the global object easily.

Maybe there can be a way to configure/pass the document object to testing-library? That would make it easy to swap the DOM library.

@Industrial
Copy link

@kentcdodds Can we open this ticket again? Being able to do proper component tests will make Deno a much more reliable platform for doing React apps.

Would be great if the https://github.com/denoland/fresh starter would include some component tests as an example and used react-testing-library.

@kentcdodds
Copy link
Member

If someone wants to work on that it's great by me! I don't have the bandwidth to work on it personally. As far as I'm aware, nothing has changed since my last comment on this so I don't see a reason to reopen 🤷‍♂️

@john-griffin
Copy link

I was eventually able to get this working but it's very messy, summarized here https://github.com/john-griffin/deno-dom-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants