Home > Back-end >  How to include lib to karma tests?
How to include lib to karma tests?

Time:09-26

I'm trying to use external libs in tests. I added all needed links in karma.conf.js and some libs were included without any problem. But for some libs karma sets "undefined" instead of "this" when compiling they, like this:

Karma sets undefined

And of course, then I have errors because of it:

Errors in console

What could I do wrong? Is it possible to include such lib?

CodePudding user response:

In a JavaScript module, this is undefined at the top level (i.e., outside functions). Because of that, Rollup will rewrite any this references to undefined so that the resulting behaviour matches what will happen when modules are natively supported.

To solve it you can use options.context and options.moduleContext to change this behaviour. Like this: context: 'window'

  • Related