0

I am using Jasmine to unit test some legacy code that will run in the browser. Here is how I execute my tests: ts-node node_modules/jasmine/bin/jasmine

Because this is legacy code, it's using globals (ie: window). How do I execute Jasmine and tell it that it should assume the code is in browser mode as opposed to node mode. That is, recognize window as a global variable and global as not?

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356

1 Answers1

0

If jasmine is a hard requirement, you can use jsdom to mimic browser environment in node.

const jsdom = require("jsdom");
const { JSDOM } = jsdom;
global.window = (new JSDOM()).window; // this will put window object on the node's global object.

If it is not a hard requirement, consider using jest, which has the entire jsdom setup built-in.

felixmosh
  • 32,615
  • 9
  • 69
  • 88