AngularJS Testing

Testing Directive

http://www.youtube.com/watch?v=rB5b67Cg6bc

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.

References

Notes

  • 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

// list of files / patterns to load in the browser
files = [
  JASMINE,
  JASMINE_ADAPTER,

  // libraries
  'test/javascripts/lib/angular.js',
  'test/javascripts/lib/angular-resource.js',
  'test/javascripts/lib/angular-sanitize.js',
  'test/javascripts/lib/angular-mocks.js',
  'test/javascripts/lib/jquery.js',

  // sources
  'app/assets/javascripts/word.js',
  'app/assets/javascripts/date_helper.js',

  // tests
  'test/javascripts/src/*.js',
];
Advertisements

Posted on June 11, 2013, in JavaScript, Software Design. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: