Before starting, this is not a duppe of ReferenceError can't find variable: $
I'm writting tests in TypeScript
with Karma
. My code makes use of $
for a simple fact, that the application we run our App uses jQuery, but we don't, so instead of installing jQuery we only declare the variable in a globals.ts
file:
declare var $: any
The code works just fine, no problems. But the tests fail:
ReferenceError: Can't find variable: $
in my Karma.conf.js
I already make reference of all ts
files, this includes the global.ts
with the global variabel $
:
// list of files / patterns to load in the browser
files: [
'init-test-bed.spec.ts',
'src/**/*.ts',
// 'src/**/*.html',
{ pattern: 'node_modules/babel-polyfill/browser.js', instrument: false }
],
but it doens't work.
Is this a problem with es6
? Or what am I missing? Why does my code work and my test doesn't? This is for sure something with karma configuration, but I cannot find out what.
EDIT:
I found a workaround, I don't think that is the solution because I don't want to reference jQuery, all I want is to have a global scoped variable:
// list of files / patterns to load in the browser
files: [
'init-test-bed.spec.ts',
'src/**/*.ts',
// 'src/**/*.html',
{ pattern: 'node_modules/babel-polyfill/browser.js', instrument: false },
'https://code.jquery.com/jquery-1.11.2.min.js'
],
where I referenced jQuery, I should be able to declare my global.ts
wchich contains my global variable $
, but karma doesn't seem to like it.