Problems with Bun and Happy-DOM? TypeScript complains of Matchers? #595
cpt-westphalen
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This started at oven-sh/bun#1825, the Bun repo. This was my answer there, but here it might help others in the same situation.
Problem is TypeScript is not correctly extending the Matcher to the types of jest-dom by itself.
Bellow is my original answer / tutorial:
I'm not experienced at configuring stuff, as you may notice by it, but I kept thinking: if someone's smart enough to code the thing I should be at least smart enough to find out how to use it, lol.
Anyway, for anyone who falls here and needs to know how to configure bun with happy-dom and jest-dom with TypeScript and working code completion, that is how I did it in Vite for working with React:
How to configure Bun + Jest-DOM + Happy DOM in Vite (TypeScript React)
Add dependencies with
bun add
:bun add -D happy-dom @happy-dom/global-registrator @testing-library/jest-dom @types/web
Add this key to the
compilerOptions
intsconfig.json
file:happydom.ts
file inside your src folder with the following (this will be pre-loaded so it works in every test file):It is ugly, I know. It works, so I'm not touching it again so soon.
bunfig.toml
file (or create a file namedbunfig.toml
at the root level of the project, next topackage.json
):If you want to place the happydom file somewhere else, just make sure it is being parsed by TypeScript.
.d.ts
extension (jest-dom-types.d.ts
, for example) and this code:expect
as you normally would in your test file:import { describe, expect, it } from "bun:test";
Beta Was this translation helpful? Give feedback.
All reactions