How to include custom .js file to Angular-CLI karma tests
Versions
<!--
Output from: `ng --version`.
If nothing, output from: `node --version` and `npm --version`.
Windows (7/8/10). Linux (incl. distribution). macOS (El Capitan? Sierra?)
-->
Angular CLI: 1.5.4 Node: 8.0.0 OS: win32 x64 Angular: 5.0.3 ... animations, common, compiler, compiler-cli, core, forms ... http, platform-browser, platform-browser-dynamic ... platform-server, router
@angular/cli: 1.5.4 @angular-devkit/build-optimizer: 0.0.33 @angular-devkit/core: 0.0.21 @angular-devkit/schematics: 0.0.37 @ngtools/json-schema: 1.1.0 @ngtools/webpack: 1.8.4 @schematics/angular: 0.1.7 typescript: 2.6.2 webpack-bundle-analyzer: 2.9.1 webpack-merge: 4.1.1 webpack: 3.8.1
windows 10
Repro steps
I'm stuck trying to load up our custom .js files with new migration to angular-cli.
We have some scripts that extend/customize leaflet maps for us and defines some classes.
While the build works, the karma tests complain they cannot find the classes defined in these classes.
I've added the files to the assets folder, added them to scripts in angular-cli config, added them to files in karma.config, I've played around with the typings, but there is so much in these files, typings seems like too much but maybe i'm not understanding something there?
Confused on how/why the karma tests cannot find these .js files.
For example we have created a .js file with this at the very top:
L.ScMarkerTypes = { Alarm: 0, Platform: 1, Patrol: 2, Location: 3 } ng build works correctly, but ng test reports many things like:
Property 'ScMarkerTypes' does not exist on type 'typeof L'.
we've migrated from systemjs, to webpack to webpack aot to angular-cli and this has always just worked for unit tests. not sure what has changed for angular-cli and karma
am i missing the best practice on including a 1-off .js file?
Observed behavior
<!-- Normally this includes a stack trace and some more information. -->
The properties and 'extend's defined in the .js file are not found and throw errors
Desired behavior
Mention any other details that might be useful (optional)
I'd like to help you but the problem you're describing is a bit more vague than you realize. It's hard to figure out where the error is coming from and how things are failing. Can you setup a minimal repro please?
You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.