#Can't find variable: document

1 messages · Page 1 of 1 (latest)

half thicket
#

When running Bun test with @testing-libary/react i keep getting this error is there any way to stop it

Can't find variable: document

normal moon
slate wedge
#

the I am referring to the above doc and it throws an error, given in the screenshot.

My tsconfig.json file is

{
"compilerOptions": {
"lib": ["esnext", "dom"],
"module": "esnext",
"target": "esnext",

 // if TS 5.x+
 "moduleResolution": "bundler",
 "noEmit": true,
 "allowImportingTsExtensions": true,
 "moduleDetection": "force",

 // best practices
"strict": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"composite": true,
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"types": [
  "bun-types", // add Bun global
  "@types/web"
]

}
}

Is there any issue in configuration? Please help

normal moon
#

I see, this is a runtime error

#

Bun doesn't implement document because it's browser API

#

In a testing environment you'll have to use a library like happy-dom to provide implementations of these browser APIs