简体   繁体   中英

Unit Testing for Angular 2 App Using Jasmine Karma Without Webpack

Can Jasmine-Karma be implemented for Unit Testing in Angular 2 application without using Webpack? Instead of Webpack, SystemJS is a solution but is it correct to use SystemJS and Webpack in an application simultaneously? I'm using Webpack for development mode and production mode of the application.

Karma and Jasmine has nothing to do with Angular2, they're separate libraries that could run completely separately.

For Karma to run, you'd need :

 npm install -g karma-cli
 karma init my.conf.js // this will create a configuration file for Karma
 karma start my.conf.js

This will look for all your test files and run them and then shows the result in the command line.

But, the problem is when you're dealing with Angular2 code which you normally write in Typescript and the code itself might have some extra dependencies, the Karma configuration might become painful. You might have sass files that needs to be converted into css files first for Karma ( you can think of Karma as the browsers, it needs only JS and CSS and HTML, nothing more).

And like I said, you'd need your typescript code to first be transpiled to Javascript to give it to karma right?

So you need someone to handle this small tasks for you, which is normally webpack in this days, and used to be gulp and grunt.

Webpack is a sophisticated bundler and it does almost everything you might ever need when working with Angular.

I wouldn't recommend using SystemJS and Webpack together because Webpack already does what SystemJS does ( loading files and ... ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM