After watching several videos from Mr. Miško Hevery, I’m getting to understand more on the testability consideration in AngularJS. Along with the modular design of framework itself, it has nice helper methods for testing which allows to easily test directives which involves HTML (DOM) interaction. Also, as described in the above tutorial, Karma (Testacular) provides very nice way to run test codes.
The followings are some notes when I configured the environment.
The official github site, which provides some instructions to install. After the installation, just adding location of files in the configuration file (“karma.conf.js”) is enough. Then “karma start” command automatically picks up related files in real time.
Some AngularJS testing samples. It’s good to refer working examples, as it’s a little to tricky to load or inject dependencies for AngularJS related modules.
- I’m now using Rails backend for angular-resource with ‘angularjs-rails’ gem file. As gem file doesn’t provide libraries in each project folder, I’ve separately downloaded and stored in the testing folder (not sure if there’s any good way to refer gem file content location).
- “angular-mocks.js” is required to use “inject” and “module” testing helper functions. Otherwise, it throws “not defined” errors.
- In karma.conf.js, list files in libraries -> sources -> tests order. Otherwise, it can show “not defined” errors.
excerpt – karma.conf.js