jest-environment-jsdom-global icon indicating copy to clipboard operation
jest-environment-jsdom-global copied to clipboard

Cannot find name 'jsdom'

Open xiaoyuhen opened this issue 7 years ago • 7 comments

hello simon

In my project jest-environment-jsdom-global can run normally, But jslint will prompt me 'Cannot find name 'jsdom'

my tslint version is "^5.10.0",should i ignore this waring?

xiaoyuhen avatar May 07 '18 03:05 xiaoyuhen

Hm, strange one. I've only used eslint, but actually, the behavior you're describing is what I would have expected to happen there, too.

Since I haven't used tslint before, I'm not sure what the solution is. Ignoring may be the best option.

Open to any suggestions or PRs on this, though!

simon360 avatar May 09 '18 06:05 simon360

Add this line will solve this problem declare var jsdom: any

But I think this is not an elegant solution

xiaoyuhen avatar May 09 '18 06:05 xiaoyuhen

Another solution is to refer to global.jsdom, rather than jsdom. Again, though, this lacks elegance.

simon360 avatar May 12 '18 10:05 simon360

Any elegant solutions planned for TS users? @simon360 where are you getting global.jsdom from?

quantuminformation avatar Sep 12 '18 14:09 quantuminformation

@QuantumInformation this isn’t on my radar right now, but I’d love to see a pull request!

simon360 avatar Sep 12 '18 21:09 simon360

FYI, for others that have experienced this issue, we fixed this by referring to global.jsdom as @simon360 offered as a potential solution but we also had to declare JSDOM in our globals.d.ts file like this:

import { JSDOM } from 'jsdom';

declare global {
  namespace NodeJS {
    interface Global {
      jsdom: JSDOM;
    }
  }
}

For more information on the globals file: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/global-d-ts.html

stephanie avatar May 15 '19 14:05 stephanie

// global.d.ts
import { JSDOM } from 'jsdom';

declare global {
  namespace globalThis {
    const jsdom: JSDOM;
  }
}

easier

// global.d.ts
import { JSDOM } from 'jsdom';

declare global {
    const jsdom: JSDOM;
}

eightHundreds avatar Jul 05 '19 12:07 eightHundreds